Tag: mongodb

如何使用Java在MongoDB中使用AND和OR子句执行查询

我想在MongoDB 3.2中使用Java Driver 3.2执行查询,它同时包含$and和$or子句。 通过参考 ,我尝试了以下方法: List criteria1 = new ArrayList(); List criteria2 = new ArrayList(); criteria1.add(new Document(“fetchStatus”, new Document(“$gte”, FetchStatus.PROCESSED_NLP.getID()))); criteria1.add(new Document(“fetchStatus”, new Document(“$lte”, fetchStatusParam))); criteria1.add(new Document(“episodeID”, new Document(“$in”, episodeIDs))); criteria2.add(new Document(“fetchStatus”, new Document(“$eq”, PROCESSED_FETCH.getID()))); criteria2.add(new Document(“isFullTextRet”, new Document(“$eq”, false))); BasicDBList or = new BasicDBList(); or.add(criteria1); or.add(criteria2); DBObject query = new BasicDBObject(“$or”, or); ArrayList […]

如何避免exception使用mongoDB Java驱动程序3.4+或3.6+过早地到达流的末尾? (插入期间)

我正在尝试使用以下代码片段将一些文档插入到上限集合中: // get document with specific fields Document found = collection.find().first(); String getTitle = (String) found.get(“title”); String getUrl = (String) found.get(“url”); String getImg = (String) found.get(“img”); String getPrice = (String) found.get(“price”); // document which I want to get as new Document doc = collection.find(new Document(“title”, getTitle) .append(“url”, getUrl) .append(“img”, getImg) .append(“price”, getPrice) .append(“sent”, true)).first(); // […]

在mongodb集合中查找一些值?

我试图用java读取(mongo)用户数据库。 在教程页面上,我看到了如何阅读整个集合。 我可以这样做: DBCursor cursor = col.find(); while (cursor.hasNext()) { System.out.println(cursor.next()); } 现在,如果我有一个用户集合:=姓名,年龄,密码(…)等等。 现在我想找一个带密码的名字。 例如,对于登录过程。 假设我有两个字符串:String n和p。 如果数据库中有user.equals(n)和password.equals(p),则登录用户。 我该如何更换光标? 我在mongodb java教程页面上看到了一些查询示例,但是我真的不明白…… 有任何想法吗? 谢谢

mongotemplate聚合与条件

我有一个文件看起来像这样的集合: { _id: “545b9fa0dd5318a4285f7ce7”, owner: “admin”, messages: [ { id: “100”, status: “sent”, note: “” }, { id: “100”, status: “pending”, note: “” }, { id: “101”, status: “sent”, note: “” }, { id: “102”, status: “sent”, note: “” }, { id: “101”, status: “done”, note: “” } ] } (这只是一个简短的例子,在我的例子中,子数组非常大) 我需要查询集合并获取特定文档的一些统计信息。 所以在这个例子中,如果我查询具有id:“545b9fa0dd5318a4285f7ce7”的doucment,我应该得到这个结果: { sent: […]

MongoDB Java拉

我尝试删除嵌入式文档而没有成功。 我正在寻找以下指令的java方式: db.games.update({‘_id’: 73}, {$pull: {‘goals’: {‘goal’: 4}}})

Mongodb 3.0 java insertOne

我正在尝试将我的遗留应用程序从Java驱动程序2.10.1升级到3.0.0所以insert方法更改为insertOne。 但DBCollection.insert()返回结果,我可以检查getError() 。 但MongoCollection.insertOne()不返回值。 如何检查操作错误?

spring-mongo-1.0.xsd错误

我收到以下错误,但无法解决它谷歌搜索也没有成果。 请帮忙。 Referenced file contains errors (http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd). For more information, right click on the message in the Problems View and select “Show Details…” 这是我的代码。 我喝了很多东西。 我觉得它有一些依赖性问题。 请帮忙。

无法通过Camel将日期字段保存为mongo db中的ISO日期?

我有这样的pojo: @Document(collection = “data”) public class DataPoint { @Id private String id; private LocalDateTime createdDate; …. } 在一些代码库中我有以下代码: @Autowired private ProducerTemplate producerTemplate; … final List dataPoints =…. producerTemplate.sendBody(“mongodb:mongoBean?database=” + mongoDataConfiguration.getDatabase() + “&createCollection=true&operation=insert&collection=” + mongoDataConfiguration.getDataPointCollection(), dataPoints); 但是当我在数据库中打开集合时,我看到这样的日期字段: “createdDate” : { “month” : “NOVEMBER”, “year” : 2017, “dayOfMonth” : 7, “dayOfWeek” : “TUESDAY”, “dayOfYear” : 311, “monthValue” […]

MongoDB嵌套文档搜索

如何搜索文档具有嵌套文档的mongodb文档。 例如,我有一组私人消息。 每条私人消息都有两个嵌套文档 – 一个代表发送用户,另一个代表接收用户。 两个嵌套文档都有以下forms – userID:34343,名称:Joe Bloggs 我希望能够搜索用户发送的所有邮件消息(例如,搜索发件人用户嵌套文档)。 我正在使用java驱动程序。 我是否需要创建一个代表嵌套文档的DBObject? 谢谢

Android Studio:使用Mongo Java Driver连接到MongoDB服务器

有很多关于这个问题的post,但似乎没有人工作,所以maby有些事情发生了变化。 我正在尝试将我的Android应用程序连接到位于mLab上的MongoDB服务器。 我正在使用Mongo Java Drived,并且当然将库添加到android studio。 可以启动应用程序,但是当我单击注册按钮时,应用程序会崩溃。 这是我的代码: import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import org.bson.Document; import com.mongodb.MongoClient; import com.mongodb.MongoClientURI; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final EditText username = (EditText)findViewById(R.id.username); final Button bRegister = (Button) findViewById(R.id.bRegister); bRegister.setOnClickListener(new View.OnClickListener() […]