I was trying to solve a query given in an assessment to fetch details from a collection. The assessment was in online editor so I had to follow the base query structure. MONGODB version 4.4
The base query was looking like below.
{
find : "MY_COLLECTION_1"
}
The collection name is "MY_COLLECTION_1", and there is field "FirstName" column in the collections like below.
{
{
"FirstName": "ABC"
}
{
"FirstName": "XYZ"
}
}
I have never seen the below format to fetch the data. Need help with this.
{
find : "MY_COLLECTION_1"
}
I tried to fetch something like below.
{
"find" : "MY_COLLECTION_1",
"FirstName" : "ABC"
}
but it's saying invalid BSON format
CodePudding user response:
The "online editor" appears to be using the find database command, which has the basic structure:
{
find: <string>,
filter: <document>,
sort: <document>,
projection: <document>,
hint: <document or string>
}
You will likely need to use the filter
field to pass in a query.