objectid

Mongo = get size of single document

半城伤御伤魂 提交于 2019-11-27 06:31:52
I encountered a strange behavior of mongo and I would like to clarify it a bit... My request is simple as that: I would like to get a size of single document in collection. I found two possible solutions: Object.bsonsize - some javascript method that should return a size in bytes db.collection.stats() - where there is a line 'avgObjSize' that produce some "aggregated"(average) size view on the data. It simply represents average size of single document. When I create test collection with only one document, both functions returns different values. How is it possible? Does it exist some other

Mongodb Join on _id field from String to ObjectId

柔情痞子 提交于 2019-11-27 04:05:50
问题 I have two collections User { "_id" : ObjectId("584aac38686860d502929b8b"), "name" : "John" } Role { "_id" : ObjectId("584aaca6686860d502929b8d"), "role" : "Admin", "userId" : "584aac38686860d502929b8b" } I want to join these collection based on the userId (in role collection) - _id ( in user collection). I tried the below query: db.role.aggregate( { $lookup: { from: 'user', localField: 'userId', foreignField: '_id', as: 'output' } } ); This gives me expected results as long as i store userId

Mongo = get size of single document

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 10:24:39
问题 I encountered a strange behavior of mongo and I would like to clarify it a bit... My request is simple as that: I would like to get a size of single document in collection. I found two possible solutions: Object.bsonsize - some javascript method that should return a size in bytes db.collection.stats() - where there is a line \'avgObjSize\' that produce some \"aggregated\"(average) size view on the data. It simply represents average size of single document. When I create test collection with