1

As far as I know you can query mongodb with FindAsync using:

  • Linq.Where
  • A lambda expression that is called for every document in a collection
  • Creating a Filter with the Builder<> class

Now:

  1. Is there a difference in performance or the way documents are loaded during the search?
  2. Is there an recommended way of searching?
  3. What is the best way to query for nested documents?
Thomas
  • 8,397
  • 7
  • 29
  • 39

1 Answers1

1
  1. Yes, there is a difference. Linq is the worst performance wise, but often the most flexible and most type safe. A lambda expression is next, then a filter, then a fourth option of simply using a BsonDocument and directly constructing mongodb query criteria. What you choose needs to fit your methodology and performance criteria. Most of the time, the overhead of LINQ is not enough to give up the type safety.

  2. No.

  3. Using one of the above 4 methods in number one. On arrays, you'll likely want to use the $elemMatch operator. Remember that embedded documents are simply embedded in the stored parent document. There shouldn't be a lot of times where you want an embedded document but not the parent document. If that happens a lot, you might considering putting the embedded documents in their own collection.

Craig Wilson
  • 12,174
  • 3
  • 41
  • 45
  • But then, why does you the mongodb blog recommend mongodb for storeing timestamps in embedded documents? http://blog.mongodb.org/post/65517193370/schema-design-for-time-series-data-in-mongodb I will always need information stored in the main document and then update or add some records to an embedded List. Perhaps you can have a look at my other question conderning this topic: http://stackoverflow.com/questions/36644120/mongodb-use-nested-document-or-separate-collections-with-references – Thomas Apr 25 '16 at 13:09
  • The answers there already seem adequate. You know your data and your use cases. You are going to have to make a decision. I'd like to suggest that it is probably well worth your time to take the classes at university.mongodb.org. Many of the questions you are asking here on stackoverflow are covered and answered there. – Craig Wilson Apr 25 '16 at 15:34
  • I already plan to take the class. Unfortunately I have to work now on this topics. Also I think my questions are quite natural for someone getting started with mongo. If the documentation would be better I wouldn't have to ask here. – Thomas Apr 25 '16 at 16:12