What is the correct way to utilize deleteMany() in the MongoDB shell when using an $and query?

I need to remove all entries in the infrastructure collection with a type.primary of "pipelines" and a type.secondary of "oil."

Currently, I'm using this query:

db.infrastructure.deleteMany({$and: [{"properties.type.primary": "pipelines"}, {"properties.type.secondary": "oil"}] })
,

However, the result is:

{ acknowledged: true, deletedCount: 0 }

This is puzzling because MongoDB Compass shows that there are 182 matching documents for the query

{$and: [{"properties.type.primary": "pipelines"}, {"properties.type.secondary": "oil"}] }

The structure of my documents looks like this:

properties": {
                "optional": {
                    "description": ""
                },
                "original": {
                    "Opername": "ENBRIDGE",
                    "Pipename": "Lakehead",
                    "Shape_Leng": 604328.294581,
                    "Source": "EIA"
                },
                "required": {
                    "unit": null,
                    "viz_dim": null,
                    "years": []
                },
                "type": {
                    "primary": "pipelines",
                    "secondary": "oil"
                }
...

According to my understanding, I should just be passing a filter to deleteMany(), where $and expects an array of objects. It's strange that the combination isn't working as expected here.

Answer №1

It suddenly dawned on me that the most straightforward solution was actually the right one - I had mistakenly spelled my database name incorrectly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Rails not receiving JSON data

I am attempting a straightforward ajax call in Rails 4, but encountering issues with retrieving the json response. Below is the script I'm working with: $(document).on "submit", "form[name=upvote-form]", -> form = $(this) $.post "/vote", $(th ...

Dynatree fails to consider the select feature while utilizing ajax requests

Currently, I am utilizing the dynatree plugin to exhibit a checkbox tree in multi-select mode (mode 3). Upon initializing the tree using ajax (without lazy loading), it appears that certain nodes that were initially loaded as selected are forgotten. When ...

Is it possible to implement JSON in place of SQLite for my Android application?

Currently, I am working on a basic android application that includes an activity dedicated to showcasing data extracted from a few tables in an online mySQL database. These tables are fairly straightforward and will not exceed 100 rows. In order for the a ...

Mastering the art of debugging a mongoose action in node.js

I am utilizing mongoose for connecting my node.js app with mongoDB. However, I am facing an issue where the database does not get updated when I create or update a model instance. How can I effectively debug and identify what goes wrong in the create or up ...

Loop through a JSON object and save references in a Swift program

Upon receiving a JSON payload from a web request, the task at hand involves extracting the data and assigning it to variables within an NSObject subclass. The object contains the following variable declarations: var name:String? var email:String? var abo ...

Analyzing User Input and Database Information with Mongodb

Here's the HTML form I'm working with: <form id="contact-form" method="POST" action="/search"> <label for="company">Phone company</label> <input type="text" name="company" value=""> &l ...

Hiccup: encountering ENOTFOUND in nodejs when making a get request

Running a web server on node, here is the code: var restify = require('restify'); var server = restify.createServer(); var quotes = [ { author : 'Audrey Hepburn', text : "Nothing is impossible, the word itself says 'I'm p ...

How to prevent ConcurrentModificationException while converting to Json format?

In our project, we have a custom class called Document that utilizes a private member of type Map<String, Object> to store data. These objects are stored in memory and often modified by multiple threads. Additionally, these objects, particularly the ...

`MongoDB impatient for query outcome`

Upon trying to pass the 'db' from my server.js file, where I establish a connection with MongoClient, to routes/api.js for post requests, I encountered an issue. The error message I consistently receive is: TypeError: Cannot read property &apo ...

Guide to sending an Array of objects in the request body using RestAssured in Java

Here is the Request I am working with: [ { "userId": "value1" },{ "userId": "value2" } ] I attempted to create a POJO class and construct the request, as well as using an ArrayList, but there ...

Unable to define replication cycle within JSON structure

Hey there, I'm currently working on implementing a copyIndex in a script to handle an array of virtual machines. You can find the full script here: https://pastebin.com/embed_iframe/vQyyKrYn The error message I am encountering states: is not valid: ...

"I am interested in using the MongoDB database with Mongoose in a Node.js application to incorporate the

I am facing a situation where I need to validate the name and code of a company, and if either one matches an existing record in the database, it should notify that it already exists. Additionally, when receiving data with isDeleted set to true, I want to ...

Query for string type data between specific dates in MongoDB

I have my data stored in this format on MongoDB: { "_id" : { "$oid" : "5385a437084ea4734b03374f" }, "linea" : 1, "egunak" : [ { "fetxa" : "2014/05/26", "turnoak" : [ { ...

MongoDB Query Yields Null Result Set

As a complete beginner, I am currently following a tutorial to grasp the fundamentals of the MEAN stack. My current challenge involves retrieving documents from my database and displaying them on a webpage, but all I get is an empty array. To provide some ...

Tips for utilizing a particular field as the title of a JSON entity while employing JsonConvert.SerializeObject

After running serializeobject, my current output looks like this: { "ID": "dog-1", "fed": [ "2016/05/19T01:00:00Z" ] }, The object I'm trying to serialize contains a string for "ID" and a List of strings for "fed." Is there a way to modify the ou ...

Retrieve the highest value from a JSON array in Excel VBA using a non-iterative method

Extracting the highest value of "id" from a JSON data string without iterating can be challenging. The given JSON data string is as follows: "ball_coordinates": [ { "id": 3938706, ...

How can I include a query parameter in a Rails API GET request?

I'm currently working on a project with a basic Item model where both "/items" and "/items.json" are functioning properly. However, I am now looking to enhance the API by adding a search parameter like "/items.json?skuid=123" so that only Items with t ...

Exploring the array of nested objects within an array of objects

Greetings, I seem to be facing a challenge with my JSON data. My goal is to extract the "tag" value from the objects within the "cows" array. Delving into nested data structures is somewhat new to me, and I've hit a roadblock in this process. Any insi ...

Using PHP to update MySQL on Android by sending data in JSON format

I attempted to create an activity that would update a MySQL database. Here is the code for the web server: <?php //error_reporting(0); require_once('db_config.php'); if($conn){ $sql = "UPDATE order_detail SET order_status ='co ...

Retrieving the value of a specific property nested within a JSON object using basic JavaScript

Hey there! Thanks for taking the time to check out my question. I'm diving into JavaScript and I've hit a roadblock trying to solve this particular problem: I'm looking to extract the value of a property nested within a JSON object under a ...