How to query by datetime in Doctrine MongoDB ODM?

Let’s learn how to query by datetime in Doctrine MongoDB ODM. The most accurate or helpful solution is served by Stack Overflow.

There are ten answers to this question.

Best solution

Doctrine Mongodb ODM and DateTime query

I could use some help on this problem. I'm creating an application using Symfony2 + mongodb + doctrine. I just want to use Doctrine ODM to query all the users who have been logged in the last 5 minutes. I have a User collection with a date field called date_last_login. So I try to use the querybuilder like that: <?php // Creating a DateTime object and susbtract 5 min from now // local time is 15:40:05, timezone: 'Europe/Paris' $_dateTime = new \DateTime(); $_interval5Min = new \DateInterval...

Answer:

This is likely due to this PHP bug which was fixed in 5.3.3: https://bugs.php.net/bug.php?id=50916

Read more

JuCachalot at Stack Overflow Mark as irrelevant Undo

Other solutions

How can I return 1.7 gb of mongodb documents when a query is made to the server in a web app?

In Spring mvc + mongodb application, I have 4 lakh documents. Assuming if I need to return 3 lakh documents when a query is made, how can I do that? Following is the stack trace, HTTP Status 500 - Request processing failed; nested exception is java.lang...

Answer:

You don't. The problem here is not some configuration setting, it's a technical misunderstanding. 2GB...

Read more

Gaëtan Voyer-Perrault at Quora Mark as irrelevant Undo

Can MongoDB index for the "$exists" query?

In some data mining scenarios, I have a MongoDB collection whose records are heterogenous (i.e. they can have different keys). I often query for "which records have a field with a given key", as in db.coll.find({"fieldname":{$exists...

Answer:

In MongoDB 1.8 $exists doesn't use indexes. In 1.9 it does[1]. 1.9 is the unstable development release...

Read more

David Mytton at Quora Mark as irrelevant Undo

Why it was necessary to use MongoDB query syntax with  "array()"  in PHP driver extension for MongoDB?

In at least Ruby and Python implementation of MongoDB driver you use nearly identical syntax for commands that are used in Mongo shell which are compact and natural. Why in PHP driver everything is polluted with array() ?

Answer:

A object in javascript is effectively a hashtable. PHP does not support a true hashtable or dictionary...

Read more

Gaëtan Voyer-Perrault at Quora Mark as irrelevant Undo

How can I query this JSON tree in MongoDB?

{     "_id" : "4f316a0e29d7f51720b03251",     "totalTime" : 1717000,     "totalDistance" : 13246.551,     "segments" :     [         {             "totalTime" : 1717000,             "totalDistance...

Answer:

You might consider using GeoJSON to define your waypoints. You can use a LineString GeoJSON encoding...

Read more

Jared Rosoff at Quora Mark as irrelevant Undo

Is it possible to use a SQL style 'union' and 'pseudo column' in a MongoDB query?

Can the following sql query be done as a mongo query?  (this would solve a big problem for me) select * from ( select attribute1, '100' from collection where attribute2 = 1 union select attribute1, '200' from collection where attribute2 = 2 )  where...

Answer:

Something like this? db.collection.find({$or: [ {attribute2: 1}, {attribute2: 2}]}).sort({attribute...

Read more

Harry Heymann at Quora Mark as irrelevant Undo

How does MongoDB shard data? And when query comes, how does it find which shard to go after?

I understand how HBase does partitioning (basically range partition on row key. And row key is sorted). I see MongoDB also does range partitioning, but key is not sorted. Then how does it work? Can anyone help to understand internals?

Answer:

> How does MongoDB shard data? This is potentially a very complicated question as sharding has lots...

Read more

Gaëtan Voyer-Perrault at Quora Mark as irrelevant Undo

Node.js: How do range query in mongoose?

In mongodb javascript, i can use find({'datetime': {'$gt':  '2011-04-01', '$lt': '2011-04-09'}}) to do range query, but can i do  it in mongoose's find? Thanks

Answer:

First, in the Schema, you need to define the type of the date field to be: {date: { type: Date, default...

Read more

Razmig Youssef at Quora Mark as irrelevant Undo

How do you perform basic arithmetic in a MongoDB query?

In SQL, you can select many fields and perform basic arithmetic on them, by creating a query such as "SELECT ((field1 + field2)/2) as relevance, title, author from..."

Answer:

It's very easy: just download SlamData, an open source project that lets you run SQL on MongoDB, and...

Read more

John A. De Goes at Quora Mark as irrelevant Undo

Advanced range query in mongodb?

There are two fields in one collection "max" and "min". I have two integers X and y. I want to perform a query like this on the collection; find all the rows whose 'min'-y <= X <='max'+y. How can i do that [updated] in pymongo...

Answer:

It is possible to pass the exact query( 'min'-y <= X <='max'+y) in javascript as suggested by...

Read more

Answer Wiki at Quora Mark as irrelevant Undo

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.