mongodb-php

MongoDB finding nested objects that meet criteria

你。 提交于 2020-01-16 05:04:13
问题 I have a MongoDB document that is structured similar to the structure below follows. I am searching based on people.search_columns.surname and people.columns.givenname. So for example, when I search for the given name of "Valentine", I want to get the document back, but Nicholas Barsaloux should not be included. Data structure: [_id] => MongoId Object ( [$id] => 53b1b1ab72f4f852140dbdc9 ) [name] => People From 1921 [people] => Array ( [0] => Array ( [name] => Barada, Valentine [search_columns

How to query mongo in php?

旧巷老猫 提交于 2020-01-13 10:17:13
问题 So I've got this simple login function that is trying to match email address with a password in the database and compare it with the user entered data via form. function login($email, $password){ $m = new Mongo("localhost"); $m->connect(); $db = $m->users; $collection = $db->test_collection; echo "<pre>"; var_dump($collection->findOne(array('name' => 'john'))); //returns correctly var_dump($collection->find(array('name' => 'john'))); //returns mongo cursor object echo "</pre>"; } I don't

MongoDB - PHP - MongoCursorException 'Cursor not found'

房东的猫 提交于 2020-01-13 09:25:10
问题 I have 2 collections: A (3.8M docs) and B (1.7M docs) I have a PHP script that I run from the shell that: loops over each record in A ~60% of the time, it does a findOne on B (using _id) does some basic math, creating a php array once the loop on all docs in a is done: 4) loop over php array 5)upsert into collection C during (1), I consistently get: PHP Fatal error: Uncaught exception 'MongoCursorException' with message 'Cursor not found' The last item processed was #8187 of 3872494. real

Order Posts by Most Votes (Overall, Last Month, etc.) with Laravel MongoDB

不想你离开。 提交于 2020-01-04 05:30:09
问题 I am trying to understand more advanced functions of mongodb and laravel but having trouble with this. Currently I have my schema setup with a users , posts , and posts_votes collections. The posts_votes has a user_id , post_id and timestamp field. In a relational DB, I would just left join the posts_votes collection, count, and order by that count. Exclude dates when need be and all that. MongoDB I am having difficulty b/c there's no left join equivalent. So I'd like to learn how to

MongoDB shell's db.stats() in php and python

天涯浪子 提交于 2020-01-01 09:05:31
问题 I can see the statistics from Mongo shell as db.stats() or db.collection_name.stats() How do I view statistics of a database, or of a collection, from PHP and Python. EDIT : I have done it in PHP but still cant do it in Python. Help? 回答1: This is how you do it in Python if you are using the PyMongo driver: connection = pymongo.Connection(host = "127.0.0.1", port = 27017) db = connection["test_db"] test_collection = db["test_collection"] db.command("dbstats") # prints database stats for "test

Doctrine2 Mongodb adding more $or operator

十年热恋 提交于 2019-12-30 07:16:07
问题 It is possible for doctrine2 ODM to create the following query? db.Product.find({ "$or": [ { "name": new RegExp("test*", "i") }, { "tags": new RegExp("public true*", "i") } ], "$or": [{ "public": false, "_id": { "$in": [ ObjectId("4e74121c4fcfa9ff7ac90000"), ObjectId("4e74121c4fcfa9ff7ac80000") ] } }, { "public": true }] }); The main issue here with doctrine2 that I dont understand is how to add addition $or in the $query? This help me with $and operator which is still missing. I'm currently

MongoDB - Aggregation - To get unique items in array

a 夏天 提交于 2019-12-30 00:37:13
问题 Here's my MongoDB collection: { "_id" : ObjectId("515d8f53175b8ecb053425c2"), "category" : "Batteries", "products" : [ { "brand" : "Duracell", "item" : [ "AA", "AAA" ] }, { "brand" : "Everyday", "item" : [ "9V", "AA", "12V" ] } ] } The output that I need is 1) Unique list of all items {["AA", "AAA", "9V", "12V"]} and 2. unique list of items per product { "category" : "Batteries", "item": ["AA", "AAA", "9V", "12V"] } I'm very new to MongoDB, and I tried different aggregations functions and

mongodb php - how to do “INNER JOIN”-like query

丶灬走出姿态 提交于 2019-12-28 13:40:27
问题 I'm using the Mongo PHP extension. My data looks like: users { "_id": "4ca30369fd0e910ecc000006", "login": "user11", "pass": "example_pass", "date": "2010-09-29" }, { "_id": "4ca30373fd0e910ecc000007", "login": "user22", "pass": "example_pass", "date": "2010-09-29" } news { "_id": "4ca305c2fd0e910ecc000003", "name": "news 333", "content": "news content 3333", "user_id": "4ca30373fd0e910ecc000007", "date": "2010-09-29" }, { "_id": "4ca305c2fd0e910ecc00000b", "name": "news 222", "content":

mongodb php - how to do “INNER JOIN”-like query

一个人想着一个人 提交于 2019-12-28 13:40:09
问题 I'm using the Mongo PHP extension. My data looks like: users { "_id": "4ca30369fd0e910ecc000006", "login": "user11", "pass": "example_pass", "date": "2010-09-29" }, { "_id": "4ca30373fd0e910ecc000007", "login": "user22", "pass": "example_pass", "date": "2010-09-29" } news { "_id": "4ca305c2fd0e910ecc000003", "name": "news 333", "content": "news content 3333", "user_id": "4ca30373fd0e910ecc000007", "date": "2010-09-29" }, { "_id": "4ca305c2fd0e910ecc00000b", "name": "news 222", "content":

Aggregate mongo data php

纵饮孤独 提交于 2019-12-25 01:51:11
问题 I have collection of 113 documents. It is data from departments of university. There are 3 types of departments: natural science departments => "chairtype" = "E", humanities departments => "chairtype" = "G", creative departments => "chairtype" = "T" Every document contains fields with the same names: "mijczjeqeo" "vmfqvfjptu" "fwtweaeeba" ... and so on 113 people fill these fields from the web form every month. 1 person fills 1 document. After filling I make history of values in every