Tips for eliminating negativity when employing hyphens

I have a question about querying in MongoDB. I currently have a query that looks like this:

db.mycollection.find({
     $text: {
        $search: "my -city"
     }
})

When running this query, it negates the term city, but I actually want to search for the exact phrase my -city. Is there a way to achieve this without negation?

The text I am trying to search for may include variations such as my-city or my - city or my -city. How can I instruct MongoDB to perform an exact string match instead of using negation as the default behavior?

Answer №1

Consider enclosing it with the characters \" ... \" as shown below

db.mycollection.find({
     $text: {
        $search: "\"my -city\""
     }
})

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

In Node.js, retrieve all users from the database and display only the users' name, id, and image, excluding

I'm trying to fetch the names, profile pictures, and IDs of all users using the User.find() method. However, this method is returning all data including sensitive information like passwords and addresses. My goal is to only retrieve the name, ID, and ...

Passing an array from PHP to JavaScript without using JSON

I'm currently working on a project for school and I've hit a roadblock. My task involves accessing a database, converting the rows into an array, and then passing it to a JavaScript file to generate a graphic using the Google Charts API. Unfortu ...

Presented is the Shield UI JavaScript sparklines chart

I'm experimenting with the new lightweight ShieldUI Sparklines chart. I've copied the code directly from this page: Now, when I try to run it on my computer, I'm encountering an unexpected issue. I can see text, but the chart itself is not ...

Sharing data between parent and child components in React

I am facing an issue with passing a dynamically generated value from child components to my parent/web component. The buttons in the child component are assigned a `value="URL"` based on MongoDB data, and I want to pass that value to my parent component us ...

Ways to locate the final child in a sequence

Can someone assist me in finding the last element of this chain, which is represented as an array in the code (Symptomaster history array)? I have implemented a recursive approach to solve this. Let me demonstrate it in the code snippet below. //example ...

Mismatch in SSL version or cipher for ExpressJS

I am encountering an issue with https in express and I am struggling to comprehend it: Here is the code snippet from my previous project (which functions correctly): index.js: var fs = require('fs'); var http = require('http'); var ...

ignore current index in for loop

I am currently facing an issue with an if statement inside a for loop. The scenario involves retrieving a list of files from the directory filesSAS, iterating through each one, and converting them from csv to JSON. After conversion, I check if the output ...

Responding to a tweet with the help of twit and Node.js

Utilizing the Twit Node.js API has presented me with a challenge. I am attempting to reply to a tweet that contains a specific keyword. My goal is for my response tweet to appear nested underneath the original tweet, much like how replies function on socia ...

Error: The React Hook "useX" should not be invoked at the top level of the code

I am facing a challenge while attempting to transfer the exception handling logic from the component to my service class: Login.tsx: import { useSnackbar } from "notistack"; // ... const Login = () => { const { enqueueSnackbar } = useSnack ...

What steps can I take to ensure that the information in my Cart remains consistent over time?

I recently built a NextJS application integrating the ShopifyBuy SDK. My implementation successfully fetches products from the store and displays them to users. Users can navigate to product pages and add items to their cart. However, I encountered an iss ...

Google Apps Scripts implementation functions successfully in Postman but encounters issues when accessed from JavaScript code

Having created a script for a Google Sheet in Apps Script, I defined it as follows: function doPost(e) { var app = SpreadsheetApp.getActive(); var sheet = app.getSheetByName('Web'); var content = JSON.parse(e.postData.contents) sheet.get ...

Asynchronous function nested within a loop

Hello there! I am currently working on converting a SQLite database to NeDb using the following code snippet: const sqliteJSON = require('sqlite-json'); const Datastore = require('nedb') const exporter = sqliteJSON('etecsa.db&apo ...

What is the process for transmitting information from an express server to a client in Next.js?

I am working on a Next.js web application that uses Express. My goal is to post data to the webpage, fetch it on the server, and then pass it on to my Next.js page. Since I am relatively new to Next.js and Express, I have included my server.js code below: ...

Does angular-sortablejs work with angular 5?

I attempted to use angular-sortables in combination with the ng-drag-drop library to sort the list items that are being dragged, but it appears that nothing is happening when I try to use it. Does anyone know if angular-sortables is compatible with Angular ...

Plugin for webpack that replaces a specified function with an alternative one

I'm currently working on a webpack plugin that has the ability to analyze code and replace a particular function with another function. Additionally, this plugin will make the new function accessible globally. class PluginName { constructor(local, ...

Troubleshooting Issues with Google Analytics Internal Link trackEvent Functionality

Using ga.js, I have encountered an issue with tracking internal links on my website. Despite successfully tracking external links and viewing real-time reports for events, the internal links are not being recorded accurately. While testing pages, the tot ...

Switch between various div elements

Looking for a way to toggle between different divs? Here's the scenario: You have a sidebar with a set of buttons. Upon entering the page, you only want the div containing the button group to be visible. However, when a specific button (e.g. Info) is ...

Error: Invalid argument type. The argument "chunk" should be either a string or a Buffer, instead of a number

Currently, I am working on a problem on HackerEarth and utilizing JavaScript for the task. Here is the code I have implemented: // Sample code to perform I/O: process.stdin.resume(); process.stdin.setEncoding("utf-8"); var stdin_input = ""; process.stdin ...

Having trouble retrieving the value of a custom directive attribute

My custom directive, named "mycomponent", has the following configuration: restrict: 'AE', templateUrl: 'template.html', scope:{ sTransactionType: '=transactionType', sStorageVariable: '=storageVariable&apos ...

Discovering the clicked button in a partial view during an onSuccess Ajax call

Within my partial view, I have implemented two buttons: Save and Preview. Both buttons are functioning as expected, with Preview enabling widget preview and Save saving data to the database. However, I am encountering two issues: I am unable to determine ...