1

mongo data example :mongo data example :

    Document query1 = doc("project", "projectId")
            .append("student", "studentId")
            .append("target", new Document().append("id","001").append("name","subject"));

    Document query2 = doc("project", "projectId")
            .append("student", "studentId")
            .append("target", new Document().append("name","subject").append("id","001"));

    db.getCollection("collection").find(query1)  //result is not null
    db.getCollection("collection").find(query2)  //result is null

why?

luckylo
  • 45
  • 4
  • 1
    Read [Query on Embedded/Nested Documents](https://docs.mongodb.com/manual/tutorial/query-embedded-documents/) in the core documentation. `"target": { "id": "001", "name": "subject" }` is different to `"target": { "name": "subject", "id": "001" }` because of the order. But querying `{ "target.name": "subject", "target.id": "001" }` does not care which order. – Neil Lunn Aug 10 '17 at 03:57
  • Why not post this as an answer? – Graham Aug 10 '17 at 04:01

0 Answers0