Reputation: 7148
I have two collections in my MongoDB database. Collection1
has a field of type Guid
(well string
really) named Col2DocRef
which references the _id
of documents in Collection2
.
I currently have a List<Guid>
representing _id
s of documents in Collection2
. I would like to find all documents in Collection1
where the field Col2DocRef
is equal to any value in the List<Guid>
.
Is this the proper way to do this by using AnyIn
?
List<Guid> guids = ... // Creating by searching in Collection2 and deserializing
Builders<BsonDocument>.Filter.AnyIn("Col2DocRef", guids);
Upvotes: 0
Views: 338
Reputation: 77896
You can directly use FindAsync()
passing the filter like below assuming that those collection have corresponding strongly typed POCO in your application interface.
List<Guid> guids = ... // Creating by searching in Collection2 and deserializing
var collection = db.GetCollection<Collection1>("Collection1");
var result = collection.FindAsync(col => guids.Contains(col.Id)).ToListAsync();
Upvotes: 1