MongoDB: how to get specific elements from array?

moti shaul

I have objects in the document that look's like:
my collections
I want to get only the elements from the 'transactions' array that their inside field 'isMatched' == false
I tried:

db.myCollection.find(
{ "transactions.isMatched": false } ,
    { "transactions.isMatched": 1 
    })

But i got all the array elements:
results

What is the appropriate query for this?

varman

You can achieve this with aggregation. $filter helps to eliminate unwanted objects.

db.collection.aggregate([
  {
    $project: {
      company: 1,
      transaction: {
        $filter: {
          input: "$transaction",
          cond: {
            $eq: [
              "$$this.isMatched",
              false
            ]
          }
        }
      }
    }
  }
])

Working Mongo playground

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to project specific elements in an Array field in MongoDB?

分類Dev

How to delete particular no of elements from array in mongodb

分類Dev

Pick specific elements from array

分類Dev

How to get all the child elements from a specific div

分類Dev

How to get matching elements from array and change array object?

分類Dev

How do I get elements from an array without repetition?

分類Dev

Adding up values from array elements in MongoDB

分類Dev

How to get distinct values from an array in mongoDB and group them by ID

分類Dev

How to compare two object elements in a mongodb array

分類Dev

how to get missing elements from array of Object? suppose my array of object is coming from server as Follow

分類Dev

Firebase: How to get elements of the specific collection?

分類Dev

How to get a specific object in mongoose with mongoDB?

分類Dev

Search for keywords in array and only get the matching elements in MongoDB using NodeJS

分類Dev

mongodb: How to delete specific key from a document?

分類Dev

Want to get a specific Element from a json array,

分類Dev

Pythonic way to cut specific elements from numpy array

分類Dev

How to get the five least repeating elements in an array

分類Dev

How to get the number of elements in a JSON array?

分類Dev

How to get specific array value in php

分類Dev

How to get a json object with specific key values, from a json array column?

分類Dev

How can I get a specific value from my JSON object without using Array.filter()?

分類Dev

How to update array elements in MongoDB instead of creating new one

分類Dev

How to create MongoDB Update query to update certain elements in an array of objects

分類Dev

in python how to replace specific elements of array randomly with a certain probability?

分類Dev

How to get arrays on output from MongoDB aggregate

分類Dev

How to get databases names from listDatabases in mongodb?

分類Dev

How to get matched sub documents from mongodb?

分類Dev

How to get a specific list from a list of lists?

分類Dev

How to Get a specific string from HashMap

Related 関連記事

  1. 1

    How to project specific elements in an Array field in MongoDB?

  2. 2

    How to delete particular no of elements from array in mongodb

  3. 3

    Pick specific elements from array

  4. 4

    How to get all the child elements from a specific div

  5. 5

    How to get matching elements from array and change array object?

  6. 6

    How do I get elements from an array without repetition?

  7. 7

    Adding up values from array elements in MongoDB

  8. 8

    How to get distinct values from an array in mongoDB and group them by ID

  9. 9

    How to compare two object elements in a mongodb array

  10. 10

    how to get missing elements from array of Object? suppose my array of object is coming from server as Follow

  11. 11

    Firebase: How to get elements of the specific collection?

  12. 12

    How to get a specific object in mongoose with mongoDB?

  13. 13

    Search for keywords in array and only get the matching elements in MongoDB using NodeJS

  14. 14

    mongodb: How to delete specific key from a document?

  15. 15

    Want to get a specific Element from a json array,

  16. 16

    Pythonic way to cut specific elements from numpy array

  17. 17

    How to get the five least repeating elements in an array

  18. 18

    How to get the number of elements in a JSON array?

  19. 19

    How to get specific array value in php

  20. 20

    How to get a json object with specific key values, from a json array column?

  21. 21

    How can I get a specific value from my JSON object without using Array.filter()?

  22. 22

    How to update array elements in MongoDB instead of creating new one

  23. 23

    How to create MongoDB Update query to update certain elements in an array of objects

  24. 24

    in python how to replace specific elements of array randomly with a certain probability?

  25. 25

    How to get arrays on output from MongoDB aggregate

  26. 26

    How to get databases names from listDatabases in mongodb?

  27. 27

    How to get matched sub documents from mongodb?

  28. 28

    How to get a specific list from a list of lists?

  29. 29

    How to Get a specific string from HashMap

ホットタグ

アーカイブ