Questions tagged [mongodb-lookup]

41 questions
17
votes
1 answer

MongoDB $lookup vs Mongoose populate

I have seen this and other similar titled questions, none answer my question. I was going through the mongoose documentation where I read MongoDB has the join-like $lookup aggregation operator in versions >= 3.2. Mongoose has a more powerful…
YulePale
  • 6,688
  • 16
  • 46
  • 95
4
votes
1 answer

MongoDB lookup Algorithmic Complexity

What is the big-o complexity of MongoDB lookup operation? Say I have n records in my MongoDB collection 'A', And n records in collection 'B', each B's document have foreign _id of A, and one specific tag eg "preOrder","directOrder", "pendingOrder"…
3
votes
1 answer

How can I use MongoDB's aggregate with $lookup to replace an attribute that holds an id with the whole document?

I have two collections: user: { "_id" : "9efb42e5-514d-44bd-a4b8-6f74e6313ec2", "name" : "Haralt", "age" : 21, "bloodlineId" : "c59a2d02-f304-49a8-a52a-44018fc15fe6", "villageId" : "foovillage" } bloodlines: { "_id" :…
xetra11
  • 7,671
  • 14
  • 84
  • 159
3
votes
1 answer

MongoDB Aggregation - $lookup performance

I'm using MongoDB 3.6 aggregation with lookup in order to Join two collections (users and subscriptionusers). var UserSchema = mongoose.Schema({ email:{ type: String, trim: true, unique: true, }, name: { type: String, …
esneyderp
  • 111
  • 1
  • 12
2
votes
0 answers

Perform lookup on all dynamic reference fields if they exist

I have a rather complicated situation that I want to solve. I have a very dynamic model that allows to reference other objects (in the same collection). The reference may be a single value or an array of references. Also, the names are not known in…
OGordo
  • 143
  • 1
  • 6
2
votes
1 answer

Lookup for documents and return only the missing values

I have 2 collections like that, being A a 1.5kk documents collection: A _id relation: { alias, ref: 'B/<_id>' } B _id name I want to query for the elements in A, that aren't in B. This is what I get so far: db.getCollection('A').aggregate([ { …
2
votes
0 answers

Can we apply Projection in model level which is applied where ever that model is accessed even in aggregate or $lookup

Mongoose provides us with the ability to apply Aggregation Hooks which works only when aggregation is applied to that particular model. userSchema.post("aggregate", function() { this.pipeline().push({$project: { _id: 1, firstName: 1, lastName: 1…
2
votes
1 answer

MongoDB $lookup in an array of object with different value

I've got two MongoDB collections and i want to replace all the ID by image object. Datset collection : { _id: 5d888b3a29cf9a5e93d80756, date: 2019-09-23T11:33:00.000Z, robot: { _id: 5d9c7caf0ad3ea493210527b, name: 'erx01' }, images:[ …
1
vote
0 answers

MongoDb $Lookup doesn't work as expected in C#

I have a C# method that returns users' property data in a particular area using $geoNear and $project. I used the below pipeline to get the result. var pipeline = new[] { new BsonDocument("$geoNear", new BsonDocument …
Shehan V
  • 164
  • 1
  • 14
1
vote
1 answer

How to get associated document who satisfy match object

In the following query, I want to fetch all verified students and their related meetings. but Trying to fetch all upcoming meetings which means meetings having at least one future date time. My writtten query fetches all verified students but also…
Mani
  • 2,391
  • 5
  • 37
  • 81
1
vote
1 answer

MongoDB aggregation make inner array in root

Hi I have two collection person and department. Those collection have the properties as below. I want to aggregate and add a inner array in to the root of the document. Please check the result I need below: person: { …
1
vote
1 answer

MongoDB - lookup - multiple collection - Result in one array

Site collection fields - _id, name Node collection fields - _id, siteId, name Device collection fields - _id, nodeId, name Sensor collection fields - _id, deviceId, name I am new with MongoDB, Expected Result (without duplicated data): [{ …
Bhavin
  • 179
  • 1
  • 2
  • 13
1
vote
1 answer

MongoDB multiple subqueries

I'm kinda new to no-sql databases, so I have a question on subqueries here. Let's imagine the following structure: Type (_id, offerId) Offer (_id, typeId, productId) Product (_id, subId) I need to find all types by subId. I have no idea on how does…
Tyulpan Tyulpan
  • 724
  • 1
  • 7
  • 17
1
vote
1 answer

How to get list of id of all ROOT documents to pass to $lookup pipeline MongoDb

I have 2 collections: users collection: { "_id": "1234141341" "name": "David", "is_active": True, "age": 20 } locations collection: { "owner": "1234141341" "type": "Point" "coordinates": [ 105.843111, 21.045752 ] } I…
1
vote
1 answer

Mongodb lookup array of elements with combined result

So these are my two documents Order document: { "_id":"02a33b9a-284c-4869-885e-d46981fdd679", "context":{ "products":[ { "id": "e68fc86a-b4ad-4588-b182-ae9ee3db25e4", "version":…
1
2 3