Mongodb 4.0 has introduced $toString
aggregation operator. So, Now you can easily convert ObjectId to string
db.collection.aggregate([
{
$project: {
_id: {
$toString: "$_id"
}
}
}
])
OR vice versa using $toObjectId
aggregation
db.collection.aggregate([
{
$project: {
_id: {
$toObjectId: "$_id"
}
}
}
])
Related Contents:
- Update MongoDB field using value of another field
- Retrieve only the queried element in an object array in MongoDB collection
- MongoDB: Combine data from multiple collections into one..how?
- Include all existing fields and add new fields to document
- mongodb count num of distinct values per field/key
- $lookup on ObjectId’s in an array
- How to filter array in subdocument with MongoDB [duplicate]
- Does MongoDB’s $in clause guarantee order
- Return only matched sub-document elements within a nested array
- MongoDB Full and Partial Text Search
- How to use MongoDBs aggregate `$lookup` as `findOne()`
- Get a count of total documents with MongoDB when using limit
- MongoDB – The argument to $size must be an Array, but was of type: EOO / missing
- MongoDB nested lookup with 3 levels
- Conditional $sum in MongoDB
- MongoDB aggregate within daily grouping [duplicate]
- How do I rename fields when performing search/projection in MongoDB?
- Mongodb Join on _id field from String to ObjectId
- Group result by 15 minutes time interval in MongoDb
- MongoDB group by array inner-elements
- Moongoose aggregate $match does not match id’s
- Search on multiple collections in MongoDB
- Check if every element in array matches condition
- Converting string to date in mongodb
- The field “$name” must be an accumulator object
- Multiple join conditions using the $lookup operator
- How to remove a field completely from a MongoDB document?
- mongodb group values by multiple fields
- Mongodb Explain for Aggregation framework
- What’s the $unwind operator in MongoDB?
- MongoDB aggregation framework match OR
- Redirect output of mongo query to a csv file
- How to join multiple collections with $lookup in mongodb
- How to execute update ($set) queries in MongoDB Compass tool?
- Printing Mongo query output to a file while in the mongo shell
- MongoDB “root” user
- Overflow sort stage buffered data usage exceeds internal limit
- Is there an “upsert” option in the mongodb insert command?
- How to stop insertion of Duplicate documents in a mongodb collection
- Select MongoDB documents where a field either does not exist, is null, or is false?
- List all values of a certain field in mongodb
- Is it possible to flatten MongoDB result query?
- MongoDB Find performance: single compound index VS two single field indexes
- Storing null vs not storing the key at all in MongoDB
- how to convert string to numerical values in mongodb
- How to insert an element to MongoDB internal list?
- In MongoDB how do you use $set to update a nested value/embedded document?
- MongoDB nested array query
- How to flatten a subdocument into root level in MongoDB?
- How to get mongo command results in to a flat file