How to query a nested document in mongo?

Let’s learn how to query a nested document in mongo. The most accurate or helpful solution is served by Stack Overflow.

There are ten answers to this question.

Best solution

How do I query a mongo document containing subset of nested array

Here is a doc I have: var docIHave = { _id: "someId", things: [ { name: "thing1", stuff: [1,2,3,4,5,6,7,8,9] }, { name: "thing2", stuff: [4,5,6,7,8,9,10,11,12,13,14] }, { name: "thing3", stuff: [1,4,6,8,11,21,23,30] } ] } This is the doc I want: var docIWant = { _id: "someId", things: [ { name: "thing1", stuff: [5,6,7,8,9] }, { name: "thing2", stuff: [5,6,7,8,9,10,11] }, { name: "thing3", stuff: [6,8,11] } ] } stuff...

Answer:

Use mongo aggregation like following : First use $unwind this will unwind stuff and then use $match...

Read more

Hans at Stack Overflow Mark as irrelevant Undo

Other solutions

Retrieving an embedded document from the a mongo document?

i had a mongo document structured as {    "id": 1,    "userId": 1,    "layout": 1,    "snapshotDetails"â–¼: {      "0": {        "id": 1,        "name": "jaison",  ...

Answer:

If you use a ODM framework like Mongoose, you can do the query that Gaetan is suggesting and then use...

Read more

Thomas Chen at Quora Mark as irrelevant Undo

How do I resolve BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] in Java Spring MVC web project?

Error Stack trace:     SEVERE: StandardWrapper.Throwable     org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.io...

Answer:

Try unpacking your war file to check if the file is in the WEB-INF folder. It clearly complains that...

Read more

Martin Stolz at Quora Mark as irrelevant Undo

Which technique is preferable aggregations  or has_child query ?

Lets say we have Parent Document for book with it's name ISBN and  short summary (and some other stuff) and child documents for chapters. I can also save "parent doc" data for every chapter as doc_values (not_analysed string) and then aggregate...

Answer:

Both solutions have different use so it's not easy to answer the question without knowing the use case...

Read more

Paweł Róg at Quora Mark as irrelevant Undo

Is a message board / forum a good use case for MongoDB?

I am building message board type system that will have hundreds of topics. I am new to programming/databases and so far the mongo style query language clicks with me better than linking a ton of SQL tables. I'm also concerned with scaling as its become...

Answer:

MongoDB is well suited to this type of use - it's a Document Store, which is all forum posts are at...

Read more

Jeremy Wilson at Quora Mark as irrelevant Undo

Is it acceptable to store json api responses directly into mongoDB, as your main document structure and work from that? Is 45kb per document workable?

I am looking to develop a simple webapp, that really relies on 3rd party API's and I can't see why I can't just query the REST endpoint, store the returning JSON into MongoDB, and then just throw that to a client-side library e.g. knockout-js. Is this...

Answer:

After attending a presentation done by Ross Lawley, I think the situation is thus: 45kb is a workable...

Read more

Sky Viker-Rumsey at Quora Mark as irrelevant Undo

Difference between a query, sub query and a nested sub query?

What is difference between a query, sub query and a nested sub query? A query within a query is called sub query, then what is actually nested sub query and some people say that a query in WHERE clause of another sub query is called nested sub query...

Answer:

I believe your confusion may be because of lax terminology used by the SQL/database community. I will...

Read more

Alec Maddison at Quora Mark as irrelevant Undo

Is it possible to combine multiple columns of different formats in a single field in a Microsoft Access select query by creating nested IIF statements?

For example, here is the code that I am trying to implement. It works with two nested IIF statements of different format, but I get "#Error" for text format values and a date for long integer values when I add a third nested statement. Original...

Answer:

Normally you use the & or + sign to concatenate multiple columns into one field in a query. The...

Read more

Nico Altink at Quora Mark as irrelevant Undo

How can we mathematically prove that a nested SQL query cannot be unnested?

For example, the following nested SQL query cannot be unnested: SELECT AVG(salary) FROM ( SELECT DISTINCT department, salary FROM emp )

Answer:

Assume department1 has 10 employees with salary "$1".  department2 has 25 employees with salary...

Read more

Bill Karwin at Quora Mark as irrelevant Undo

What are good hints that a nested SQL query cannot be unnested?

For example, the following nested SQL query cannot be unnested: SELECT AVG(salary) FROM ( SELECT DISTINCT department, salary FROM emp )

Answer:

Why couldn't it be unnested? You're getting a distinct list of department and salary, but then you're...

Read more

Grant Fritchey at Quora Mark as irrelevant Undo

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.