使用Spring Boot的MongoDB查询

问题描述 投票:0回答:1

我面临与从MongoDB集合中获取数据有关的问题。我在MongoDB数据库中有以下集合:

    { item: "journal", qty: 25, tags: ["blank", "red"], dim_cm: [ 14, 21 ] },
    { item: "planner", qty: 75, tags: ["blank", "red"], dim_cm: [ 22.85, 30 ] },
    { item: "postcard", qty: 45, tags: ["blue"], dim_cm: [ 10, 15.25 ] }
 ])```

I have a below query:

 ```db.inventory.find( { dim_cm: { $gt: 25 } } )```

 Result:  ```***{ item: "planner", qty: 75, tags: ["blank", "red"], dim_cm: [ 22.85, 30 ] }***```

 However, I want the result should be:

  ```{ item: "planner", qty: 75, tags: ["blank", "red"], dim_cm: [ 30 ] }```

 Is it possible to get mentioned result. I have tried different ways but unfortunately I am unable to find any solution towards it.


mongodb mongodb-query spring-data-mongodb
1个回答
0
投票

将查询更改为此用途$gte

db.inventory.find( { dim_cm: { $gte: 25 } } )
© www.soinside.com 2019 - 2024. All rights reserved.