All Questions
Tagged with mongodb-query javascript
1,231
questions
0
votes
0
answers
49
views
MongoServerError: E11000 duplicate key error when trying to add a video to a playlist in MongoDB
I'm working on a MERN stack application where I have a Playlist document in MongoDB that looks like this:
{
_id: new ObjectId('663296c9ca082f17ba715a4c'),
name: 'My Fav 02',
videos: [ new ...
1
vote
1
answer
58
views
Mongodb has 500 million documents and i want to search with regEx based on two fields in javascript driver not schema
My MongoDb has around 500 million documents looking like the following:
{
"_id": objectId,
"Name": "John Smith",
"Address": "132, My Street, Kingston,...
1
vote
2
answers
62
views
Mongodb finding $near by data in array of objects
I'm trying to retrieve one specific object from an existing array inside the DB document, using wildcards $near and $geometry.
I have a model that looks like this:
const schema = new mongoose.Schema({
...
3
votes
1
answer
73
views
How to update a nested key containing a dot?
In a document like this:
[
{
a: "",
b: 1,
"createdAccounts": {
"[email protected]": {
"id": ["a", "b", "c"...
0
votes
3
answers
69
views
How to search in all object keys?
Given multiples documents containing a key named userId, where this key is always an object:
{
"_id": {
"$oid": "22fc6b11a0ff111d598b114f"
...
1
vote
0
answers
39
views
MongoDB Find Id in Array without knowing nested object path
QUESTION
I need to query data that is stored in mongo and find a particular id within an array without knowing the name of the sub key. In my example below, I am trying to find "AA" within ...
0
votes
2
answers
45
views
Sorting on collection documents based on array field in mongodb
Below is sample doc of collection.
{
name:"sam",
age:20,
hobbies: [ {id:1, value: "football"}, {id:2 value:"chess"} ]
},
{
"name": "Bob",
"...
2
votes
1
answer
63
views
How to update a collection item without removing non existing values send on the query?
Given this simple example, an item saved as:
{
"test": {
"a1": "a1"
}
}
When i call collection.updateOne with $set and the following object:
await collection....
2
votes
2
answers
141
views
MongoDB: How to set timestamp during insertOne() without using new Date() for insertOne() like NOW() in PostgreSQL
time: { $currentDate: { $type: "timestamp" } } });
It's not working for insert()
can you help me, anyone?
1
vote
1
answer
66
views
Get users by first_name + last_name both in mongodb
The search in my application is not working properly. For eg: If name is "John Smith" and I search by John only (first_name) , I get all the documents by name John and If I type "Smith&...
1
vote
1
answer
60
views
How to add auto incrementing number field in aggregation query?
I have used the query shown here to generate new field using $setWindowFields, but it's causing a memory issue.
I need a new field which should give numerical incrementing values.
This query causes ...
1
vote
2
answers
55
views
How to find documents that aren't referenced by a document from another collection
I have two models called session and unreadcount. I need to get that particular session count from another table. Below are my two MongoDB models.
var UnreadCountSchema = new mongoose.Schema({
...
0
votes
1
answer
134
views
How to upsert multiple object by array in JS?
I have an array with an objects from which for each object i need to find if some key exist then it should update or else insert. I have done this from for loop but problem is i have approximately 20L ...
0
votes
1
answer
74
views
Express.js Route Returns Null Value for Database Query Using _id Field
I have the following Express.js route
router.post('/', async (req, res) => {
try {
console.log(`Request Body :\n${req.body}`);
const {orderIDs} = req.body;
console....
1
vote
1
answer
45
views
Populate different fields in a mongoose query
I have the following models:
User:
const userSchema = new mongoose.Schema(
{
name: { type: String, min: 3, max: 20, required: true },
email: { type: String, required: true, unique: true },
...