Hi everyone, Thanks for reading this issue.
The query for querying document in the Vscode’s playground is as below
Read One Document
To read one document, use the following syntax in your Playground:
db.collection.findOne(
{ <query> },
{ <projection> }
)
here
But I tried it on the Vsode with no response.
However, when I clicked the choice “Search For Documents” on the left, the coming up query works well
// The current database to use.
use('poem');
// Search for documents in the current collection.
db.getCollection('chinese')
.find(
{
/*
* Filter
* fieldA: value or expression
*/
},
{
/*
* Projection
* _id: 0, // exclude _id
* fieldA: 1 // include field
*/
}
)
.sort({
/*
* fieldA: 1 // ascending
* fieldB: -1 // descending
*/
});
Did I make any mistake(。 ́︿ ̀。)? Thanks.
steevej
(Steeve Juneau)
2
Most likely you do not have a document with id:1 in the collection chinese of the database poem.
Please share the documents you get when
Thanks for your reply. ^ ^
I just query the document successfully.
Seems caused by syntax error. When I typed use('poem'); instead of use poem;. The query works fine.
Sorry for this. I should’ve be more careful when reading document.
steevej
(Steeve Juneau)
4
You did not mentioned syntax error in the first post, but indicated that you did not get any results. Your screenshot also indicate no result rather than syntax error. As far as I know, at least for mongosh, use Database and use( ‘Database’ ) both produces the same result:
Atlas rent-shard-0 [primary] test> db.chinese.find()
/* no output */
Atlas rent-shard-0 [primary] test> use poem
switched to db poem
Atlas rent-shard-0 [primary] poem> db.chinese.find()
[ { _id: ObjectId("62d831294569ddb647f8d87e"), x: 369 } ]
Atlas rent-shard-0 [primary] poem> use test
switched to db test
Atlas rent-shard-0 [primary] test> db.chinese.find()
/* no output */
Atlas rent-shard-0 [primary] test> use( 'poem' )
switched to db poem
Atlas rent-shard-0 [primary] poem> db.chinese.find()
[ { _id: ObjectId("62d831294569ddb647f8d87e"), x: 369 } ]
I still think that
Please post a screenshot with
use( 'poem' ) ;
db.chinese.find( { "id" : 1 } ) ;
and
use poem ;
db.chinese.find() ;