MongoDB: find() query to select nothing

What's an elegant way to set the query parameter so find() intentionally returns no documents?

Obviously I could just hardcode a query that I know would never return a result for my dataset. But that would be no fun.

--------------Solutions-------------

you won't gonna save negative _id. So you can try:

db.collection.find({"_id":-1})

Query on _id field like following use any one of this :

db.collectionName.find({"_id":0})
db.collectionName.find({"_id":""})
db.collectionName.find({"_id":null})

Category:mongodb Time:2019-01-09 Views:3
Tags: mongodb

Related post

  • How define conditional "Field Selection" in mongodb 'find()' query? 2011-10-21

    Is it possible to conditionally specify the fields returned by the query. Here is my use case: I have an object with nested user conversations as follows: { "_id" : "someId", user_id: 'user1', conversations: [ { user_id: 'user2', comments: [ { user_i

  • Inconsistent results being returned by mongodb find query 2011-08-17

    I ran the following query on a collection in my mongodb database. db.coll.find({field_name:{$exists:true}}).count() and it returned 2437185. The total records reported by db.coll.find({}).count() is 2437228 . Now when i run the query db.coll.find({fi

  • MongoDB find query with $and $or and $nearSphere in php 2014-12-01

    After quite some trying out and web research I go crazy with this query. I want to build a query for 'Clubs' around a geo point (distance max 500 meters) in php on MongoDB. But when I run query it ignores the distance limit and shows all clubs in dat

  • Why does the Entity Framework's DbContext.Find() generate a query with select top 2? 2011-10-19

    Why does the Entity Framework's DbContext.Find() generate a query with select top 2 and a derived table? By definition, the query is looking up by primary key which should be unique. --------------Solutions------------- Find checks first if the entit

  • Query from Vava to MongoDB: find event in a specific date range 2015-02-09

    I've got the following document in MongoDB: { "_id" : NumberLong(44), "_class" : "la.test.app.server.model.Event", "orgId" : NumberLong(2), "typeCode" : 1, "title" : "Test for notification", "shortDescription" : "Test for notification", "description"

  • How can my Meteor project reliably display information through a server-side MongoDB/collection find query? 2015-03-08

    This question already has an answer here: Get Meteor Method Return Value Inside Helper Function 1 answer I am working on a meteor project but having trouble with the asynchronous functionality. I would like to be able to reliably display information

  • Efficient SQL 2000 Query for Selecting Preferred Candy 2009-06-28

    (I wish I could have come up with a more descriptive title... suggest one or edit this post if you can name the type of query I'm asking about) Database: SQL Server 2000 Sample Data (assume 500,000 rows): Name Candy PreferenceFactor Jim Chocolate 1.0

  • Rails Active Record Mysql find query HAVING clause 2010-04-10

    Is there a way to use the HAVING clause in some other way without using group by. I am using rails and following is a sample sccenario of the problem that i am facing. In rails you can use the Model.find(:all,:select,conditions,:group) function to ge

  • Why would findOne($query) work on a collection and find($query) not using PHP's Mongo driver? 2010-12-11

    I'm using PHP to talk with a Mongo use findOne($query) on a db.collection it returns a result as I would expect. But changing that command to find() returns nothing. From the shell, if you use db.collection.find() it returns all documents. Can anyone

  • Creating A Complex Tree in MongoDB And Querying For The Data 2011-07-26

    I'm trying to do something like this in MongoDB: wiki_db | +-- Programming --+ | | +-- Perl -+ | +-- tutorials --+ | +-- 1 --+ | | +---- id = 1 | | +------+---- title = Introdaction To Perl | +---- Date = 12/11/2100 | +---- Content = "Perl is .... "

  • MongoDB Database, query with LIKE 2011-08-23

    I have a MongoDB, I can query the database with 'Country' that works fine. But I now want to also search on the field 'title' with free text. As with in SQL the WHERE title LIKE '%title%' BasicDBObject query = new BasicDBObject(); query.put("country"

  • CakePHP returning the wrong column in a find query in a HABTM relationship 2011-10-11

    I've been wrestling with this find() query for a while. For reference about the tables, see the question here: CakePHP Twitter-clone: Can't get follow-system to work. However, in short, this is for a twitter clone I'm doing for self-learning. I have

  • MongoDB $near query using Java driver 2012-02-19

    I have some shops with products on them in my MongoDB db following this data model: Shop { idShop, name, location {lat, lon}, products [] of int } If I run the following command in the mongoDB default console: db.shops.find({products:1, location:{$ne

  • SQL query for selecting products with same ingredients of other products 2009-09-08

    I have a database that stores products "available on the market" and products "still in development" in two separate tables (market_product and dev_product). A third table (substance) contains all substances a product can made of. Other two tables (m

  • SQL query to select all columns in a table except two columns 2009-12-03

    I have a table in ms-access with column names A to H TableA A B C D E F G H how can i write a query to select all columns except B and F columns. Query result should be A C D E G H Do we have something like this select * from TableA except B, F ? ---

  • What's wrong with this MySQL query? SELECT * AS `x`, how to use x again later? 2009-12-30

    The following MySQL query: select `userID` as uID, (select `siteID` from `users` where `userID` = uID) as `sID`, from `actions` where `sID` in (select `siteID` from `sites` where `foo` = "bar") order by `timestamp` desc limit 100 …returns an error: U

  • Help Forming An SQL Query That Selects The Max Difference Of Two Fields 2010-03-12

    I'm trying to select a record with the most effective votes. Each record has an id, the number of upvotes (int) and the number of downvotes (int) in a MySQL database. I know basic update, select, insert queries but I'm unsure of how to form a query t

  • Unable to convert a SQL statements (uses a HAVING clause and a temp table) to a Rails regular .find query finder. 2010-05-12

    I can't get the following SQL query to work quite right in Rails. It runs, but it fails to do the "HAVING row_number = 1" part, so I'm getting all the records, instead of just the first record from each group. A quick description of the query: it is

  • problem with find query 2010-05-13

    I have a problem with find query: $userInProjects = $this->Timesheet->RegularPost->UserInProject->find('all', array('conditions' => array('UserInProject.user_id' => $id))); The result array: Array ( [0] => Array ( [UserInProject]

  • MongoDB NoRM: query nested objects using Expando 2010-07-26

    I saw this Q&A http://stackoverflow.com/questions/2900763/mongodb-norm-query-nested-objects, but it seems to apply to strongly-typed objects only. Is there a way to do a find or update a nested field on an Expando object (http://wiki.github.com/a

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.390 (s). 13 q(s)