【问题标题】:What is the best way to return the subdocument from mongo db (Spring data)从 mongodb(Spring 数据)返回子文档的最佳方法是什么
【发布时间】:2016-12-07 20:10:25
【问题描述】:

对于一个名为“test”的集合:

{ "_id" : ObjectId("5848604af8ea274676b6asd8"), "test2" : { "_id" : null, "name" : "test3" } }

有没有办法让 mongo 直接返回“test2”类型的子文档而不是父文档? (使用spring-data-mongo)

【问题讨论】:

标签: mongodb spring-data-mongodb


【解决方案1】:

是的,您可以使用 distinct 投影找到相同的结果。 如果您的集合名称是 test then-

请运行-

db.test.distinct("test2")

【讨论】:

  • 承认有点晚,但感谢您的回答,它做到了我想要的。
  • @Rakesh 您能否将其标记为正确答案。它也会帮助其他人。提前致谢
猜你喜欢
  • 2021-09-23
  • 1970-01-01
  • 2010-09-07
  • 1970-01-01
  • 2020-01-03
  • 1970-01-01
  • 2010-10-16
  • 1970-01-01
相关资源
最近更新 更多