如何從 java 程序運行 mongo 查詢? (How to run a mongo query from java program?)


問題描述

如何從 java 程序運行 mongo 查詢? (How to run a mongo query from java program?)

我們從 mongo‑shell 運行的查詢,我想從 java 程序運行相同的查詢。我該怎麼做?


參考解法

方法 1:

I believe what you are looking for is mentioned in the comment in the answer to Create a Mongo query in Java using a String in that the library Jongo is what you are looking for. See http://jongo.org/ . Looks like not 100% the same e.g. db.collection.find(QUERY) becomes friends.find(QUERY) where query is a string. But it is closer than making the entire query into a DBObject.

(by Sumit BharatiCervo)

參考文件

  1. How to run a mongo query from java program? (CC BY‑SA 2.5/3.0/4.0)

#mongo-shell #mongo-java #mongoDB #mongo-java-driver






相關問題

Windows 是否有任何 mongo shell 擴展? (Is there any mongo shell extensions for windows?)

獲取查詢中所有文檔的大小 (Get the size of all the documents in a query)

如何從 java 程序運行 mongo 查詢? (How to run a mongo query from java program?)

MongoDB 更新 ObjectId 字段 (MongoDB update ObjectId field)

MongoDB - 將簡單字段更改為對象 (MongoDB - change simple field into an object)

mongoDB aggregate() 在電子郵件對象集合中查找電子郵件時間 (mongoDB aggregate() finding email times in a collection of email objects)

指定在 mongodb .js 腳本中使用哪個數據庫 (Specify which database to use in mongodb .js script)

命令失敗:MongoError:CMD_NOT_ALLOWED:配置文件 (command failed: MongoError: CMD_NOT_ALLOWED: profile)

有沒有辦法在 MongoDB 的一個語句中添加遞增的 id? (Is there a way to add an incrementing id in one statement in MongoDB?)

運行 rs.initiate() 後 mongodb 副本集錯誤“...replSetHeartbeat 需要身份驗證...” (mongodb replica set error "...replSetHeartbeat requires authentication..." after running rs.initiate())

將 mongo shell 連接到受限的 MongoDB Atlas 數據庫? (Connect mongo shell to restricted MongoDB Atlas Database?)

[MongoDB]:更改所有數組字段中的值類型 ([MongoDB]: Changing the type of values in all array fields)







留言討論