简体   繁体   中英

Mongo DB Wrong query lead to connection drop

I was starting the mongodb tutorial, when testing the interactive session, I found something strange:

Example:

I type:

db.articles.insert( {title:"Hello"} )
db.articles.find()

Output:

{ "_id" : ObjectId("54ee5bd6bc77893733507b43"), "title" : "Hello" }

Strangely when typed:

db.articles.find("1")  < - Wrong syntax

Output:

Wed Feb 25 20:47:29.022 DBClientCursor::init call() failed Error: error doing query: failed Wed Feb 25 20:47:29.024 trying reconnect to 127.0.0.1:27017 Wed Feb 25 20:47:29.025 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017

So, is this the expected behavior? Syntax wrong = Drop connection with no chance of recovery, or there is something wrong here?

yes! mongodb-->find() and mysql -->SELECT if you search document use this sample //insert 2 documents

db.articles.insert({title:"Hello"})
db.articles.insert({title:"world"})

//find the douments

db.articles.find()
{ "_id" : ObjectId("54ee5bd6bc77893733507b43"), "title" : "Hello" }
{ "_id" : ObjectId("54eeb06b1cdcaf474b904ad8"), "title" : "world" }

//find the first document

db.articles.findOne()
{ "_id" : ObjectId("54ee5bd6bc77893733507b43"), "title" : "Hello" }

//search

db.articles.find({title:"world"})
{ "_id" : ObjectId("54eeb06b1cdcaf474b904ad8"), "title" : "world" }

db.articles.find({title:"world"},{_id:false})
{ "title" : "world" }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM