Questions tagged [mongodb-query]
This tag is for questions related to querying and updating MongoDB collections, either through the mongo shell or using a programming language driver.
15,607
questions
0
votes
0
answers
12
views
How to filter MongoDB documents based on one specific document's array?
I have a collection like this:
{
_id: "blabla",
userName: "blablabla",
..
interactedUsers: [
"blabla2"
"some other user's id",
"some ...
0
votes
0
answers
7
views
Searching for a particular field in mongodb with laravel
So I am contiuning a project that I have asked question about previously now I have reached a stage where I am able to search with some values but it searches for every possible output that contains ...
0
votes
0
answers
3
views
Mongoose Returning null Reference of Property on Query
I have two simple models defined in Mongoose, composed of two schema Client and City, I have the property city defined in Client as a ObjectId, ref: 'City', so far so good.
If I query for a client and ...
0
votes
1
answer
11
views
Mongo DB how to find orphans in a tree?
I have the trees collection with objects which have a tree like structure. I'm using child references pattern actually, but in my case the depth of each tree is undefined - it could be in range [0:100]...
-1
votes
1
answer
23
views
MongoDB: Need to match two fields in a lookup
I've indexed nuit, regNumber and _id for a faster query.
You can find sample data and a solution which i'm not happy with because using $unwind and $lookup makes it iterate a million documents: https:/...
0
votes
0
answers
12
views
Mongodb Java - Update document replacing a string in field
I am looking for a way to update a document replacing a substring of a field with another value.
For example, in my database i have the following field:
{
"_id": 1,
"value":...
0
votes
1
answer
14
views
MongoDB - How to use $graphLookup then $group and $sort after
Suppose I have this dataset:
[
{
_id: '1',
name: 'test1',
children: ['test2', so on...],
status: 'enabled',
version: 1,
}...
0
votes
1
answer
12
views
MongoDB exclude field from document update request
sorry for my english, I used google translator :D
Is it possible during an update request using some operator to ignore a certain field of the object that we pass in the request without touching the ...
1
vote
2
answers
17
views
Is there a way to project max value in a range then finding documents within a new range starting at this max value in just one aggregate?
Given the following data in a Mongo collection:
{
_id: "1",
dateA: ISODate("2021-12-31T00:00.000Z"),
dateB: ISODate("2022-01-11T00:00.000Z")
...
0
votes
2
answers
19
views
MongoDB Aggregate Query to find the documents with missing values
I am having a huge collection of objects where the data is stored for different employees.
{
"employee": "Joe",
"areAllAttributesMatched": false,
"...
0
votes
1
answer
21
views
Unable to search data in a mongodb database using laravel
I am trying to write a query to search the mongodb database for a specific query and return the associated information here is what I have done so far:
In Post:
<?php
namespace App\Models;
use ...
0
votes
1
answer
9
views
Join two collection in mongodb
I'm new in mongodb. Could you please tell me how to perform join operation in this. I've two collection:
Collection 1 ("user")
{
_id: "d04d53dc-fb88-433e-a1c5-dd41a68d7655",
...
0
votes
1
answer
18
views
How to get schema mongo
I tried to get the schema from a mongo base but I can only get the schema from a single record. How do I get the schema of all records?
var schemaObj = db.getCollection("dado").find({})
...
0
votes
0
answers
11
views
MongoDB Node.js driver: How to find out if findOneAndUpdate actually found a document and updated it?
I'm trying to use the Collection method findOneAndUpdate of MongoDB's native Node.js driver to find and update a document in one single operation.
I then need to perform some logic that depends on if ...
1
vote
1
answer
22
views
Mongodb - hostname/IP changed for all hosts in sharding with replica set configuration
Here is my mongo cluster (sharding with replicaset) configuration.
replica sets:
rs0 - IP1, IP2, IP3 || port - 27017
rs1 - IP4, IP5, IP6 || port - 27017
config server replica set - IP7, IP8, IP9 || ...
0
votes
1
answer
20
views
NextJs Mongodb NodeJs | best way to filter products by category
I'm new to the MERN Stack and I'm building my first project but I'm stuck on finding a way to filter products by category
I was thinking of adding a "Category" field for each item in MongoDB ...
0
votes
1
answer
29
views
MongoDB/PyMongo: upsert array element
I have the following document:
{'software_house': 'k1',
'client_id': '1234',
'transactions': [
{'antecedents': 12345,
'consequents': '015896018',
'antecedent support'...
1
vote
0
answers
102
views
Mongodb write exception: write errors: [Cannot apply array updates to non-array element groups: null]
I have the following employee data structure :
{
"_id":{
"$oid":"62836b0b3c1e2c19eaaac07e"
},
"firstname":"jean",
"lastname&...
0
votes
1
answer
21
views
Nodejs Get fetch values excluding matching field array value from Mongo
How to make a find in Nodejs to get the values excluding the Given ID.
{"_id":
{"$oid": "1"},
"image_name": "img1.jpg",
"price&...
-2
votes
0
answers
12
views
How to write Inner Join condition in MongoDB with multiple columns
I was trying to join two collections using multiple columns. I was exactly looking for an inner join output. Can some one help me on getting the query in MongoDB
-2
votes
0
answers
17
views
MongoDB get counts for time series in date
I have a collection of documents ("bookings" in Mongo (upwards of 40k) with the following data model:
{"_id": "idfield", "date": "2022-05-17", "...
-1
votes
3
answers
37
views
Laravel data not being displayed
I am trying to read data from a local collections from my mongodb database. Name of database Intuit name of collection post.
Code inside PostController:
<?php
use Illuminate\Http\Request;
use App\...
0
votes
1
answer
23
views
Getting the amount of days a person is employed - mongodb
I am new to mongodb and I have a task to calculate the amount of days a person is/was employed and get the 5 employees, who were employed for longest time. I have written some code, but the amount of ...
1
vote
1
answer
23
views
Add and update child arrays value in Mongo db
I want to add value in array of the following json structure in mongo db collection "Scdtls".
I need to add value only where "Type": "Fees" and "IsCurrentVersion&...
0
votes
1
answer
19
views
Query mongo key using list of string
I wanted to query a collection field where key is not fixed. The key would be present in List.
List<String> listStr = Arrays.asList("state.mh","state.dl");
I want to query a ...
0
votes
0
answers
40
views
Mongodb unmatch aggregate lookup
I am very new in Mongodb and nodejs. I am trying to make attendance system and have multiple collection like attendances, shifts, leaves, Holidays. In the shifts collection have Week Off and obviously ...
-1
votes
1
answer
36
views
Custom return MongoDB aggregate
I'm trying to do some testing with MongoDB and I have figured some of the simpler MySQL queries MongoDB. Now, I have this slightly more complex query.
I have this query that tells me if there was a ...
0
votes
1
answer
16
views
How to make queries on nested lists with mongodb
Context
I have a legacy mongodb with 4 collections (see models below). And my goal here is to query all observation that have at least one metadata that has the field is_valid set to false and the ...
0
votes
0
answers
6
views
MongoDB Atlas - Boost search score from external list of words
I use MongoDB Atlas' full-text search which can boost the search score (how relevant a result is for that particular search query) by specifying the path that should be weighed more. Example:
text: {
...
0
votes
1
answer
13
views
MongoDB: pullAll / pull whole nested array object by value using mongoose
I want to pull the whole nested array object if the object contains a specified string for a specific key. I'm using mongoose with nodejs:
DB before deletion:
{ _id : 1234
fallBackData: {
...
0
votes
1
answer
32
views
MongoDB Performance Issue with arrays
I'm looking for some advice on how to improve the performance of my query.
I have this user model in mongoose and I'm indexing interested_cities.
const firebaseToken = new Schema({
type: {
...
-1
votes
0
answers
10
views
how can I update specific object of inside an array of object using mongo query?
Can I use any query using which I can push some extra parameter in the all the object whereever I have name user1 in the object?
{
'id': '1',
'data': [
{
'name': 'user1',
'active': 'yes'
},
{
'name': '...
-1
votes
2
answers
32
views
Add field to mongo that contain the value of the document's length
Sample document
[{
"_id": "1111",
"name": "Dani"
},
{
"_id": "2222",
"name": "Guya",
"address": &...
0
votes
1
answer
18
views
match the key in MongoDB
I want to $match in a mongoDB, Number of documents in thousands, so looking for dynamic sol:
$doc.k equal to $info.data.k after k, $match then we have an document that contain only information that $...
-1
votes
0
answers
16
views
Is there any other way to resolve it?
While using bulk operation we are getting below error. we are getting error in mongo while using bulk operation as per details explained below. Don't know how to resolve. Can anyone help me how to ...
0
votes
0
answers
6
views
Is it possible to check the current setting of TTL in MongoDB?
How can I know the current settings of the TTL?
What method can I use to check?
0
votes
2
answers
21
views
while using save() & find({}) functions in mongoose it return SyntaxError: await is only valid in async functions and the top level bodies of modules
const mongoose = require('mongoose');
main().catch(err => console.log(err));
async function main() {
await mongoose.connect('mongodb://localhost:27017/harryKart');
}
const kittySchema = new ...
0
votes
1
answer
34
views
MongoDb - Return bulks of N elements from the end of a nested array looping backwards at each call (pagination)
I have a collection of categories, and each category has its array of _id from a different collection.
My goal is to create an infinite scrolling by giving N records every time but from the end (the ...
0
votes
1
answer
27
views
Joins in mongodb documents
I am creating an application related to e-books for both authors and readers. Schema is written in mongodb with 2 collections USERS and AUTHORS. USRES store the data of every person signed up in the ...
0
votes
1
answer
41
views
mongodb command very slow
I have 3 documents like this:
{
_id: ObjectId("..."),
_details: {
_session: ObjectId("example_1"),
},
{
_id: ObjectId("..."),
_details: {
_session: ObjectId("...
0
votes
1
answer
34
views
Update a value in a nested field?
user :["id": 1, userObj:[{"bookid": 1, "library":"Oxford", "taken":true}, {"bookid": 2, "library":"Cambridge", "...
0
votes
1
answer
28
views
How to add attribute to the result of mongoose query before res.status(200).send(result);
I am trying to build a CRUD API that query a mongodb. I want to add another attribute (temperature) to the query result before sending it back to the client. Particularly, I would like to do something ...
-1
votes
0
answers
25
views
How would YouTube store data of who liked which videos?
If Youtube uses MongoDB as their database, then how would they store the who liked which videos information?
Option 1:
Store it in the Videos collection with a field that holds a list of subdocuments ...
-3
votes
0
answers
14
views
How to add $unioun with if colloction is not on top level in mongo [closed]
following is the db schema:
user_details
users
customer_details
customers
Individual collection schema:
users: {"_id", "email"}
customers: {"_id", "email"...
0
votes
1
answer
15
views
MongoDB Group by field, count it with condition
I would like to count different hu for a shipment. So I write this query but how I can count different hu group by shipment ?
my query :
db.eventstranslated.aggregate([
{ "$group": {
&...
0
votes
0
answers
14
views
How to get decrypted values in the aggregation result by the using of getter and setter in node.js
var mongoose = require("mongoose");
const Schema = mongoose.Schema;
let CryptoJS = require("crypto-js");
function encrypt(text) {
try {
let ciphertext = CryptoJS.AES.encrypt(...
0
votes
2
answers
58
views
Access root document map in the $filter aggregation (MongoDb)
I apologize for the vague question description, but I have quite a complex question regarding filtration in MongoDB aggregations. Please, see my data schema to understand the question better:
Company {...
0
votes
1
answer
31
views
How to delete and insert with a single command in mongoDB?
So, I have a collection like this:
[{
"name":String,
"address":String,
"hobby":Array of Strings
}...]
Every hour I query an API and get the response like so:
[{
...
0
votes
0
answers
11
views
How to skip a document from retrieving in MongoRepository if it causes an error?
I'm working on a web application built using SpringBoot as backend and MongoDB as DBMS. I'm showing all the latest posts in a web page.
In the PostRepository.kt class, I'm retrieving all the latest ...
0
votes
1
answer
21
views
Mongodb query with multiple $or inside $and
I want records which if type have 0 or 2 than status should not equal to 0 and if type = 3 then ignore status.
I tried this way but not working.
db.activities.find({
$and: [
{
$...