MongoDB (from humongous) is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas. MongoDB is developed by MongoDB Inc. and is free and open-source, published under a combination of the GNU Affero General Public License and the Apache License.

Share tech news, updates, or what's on your mind.

Sign up to Post

Mongo 2.6.12

Not a mongo admin just trying to figure out an issue no one else wants to take on.

Mongo is flushing logs after 24 hours, where is that configuration set or better yet what command can I run against a collection to see the details of log retention?
Easily manage email signatures in Office 365
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

Hi There,

I have a mongodb aggregate query in PHP that is throwing an error and I can't see what I've missed in the syntax.

Versions are
mongodb =  3.6
PHP  = 7.1
mongo PHP driver = 1.3.1-1

 The query in mongo shell works and looks like this:

			$match: {
			    download_Date : {'$gte' : 20180205 }
			$sort: {
			download_Date: 1 }
			$group: {
			 _id: "$cw_product_id", batch: { $last : "$download_Date" }

Open in new window

My code in PHP fails and  looks like

$command = new MongoDB\Driver\Command([
    'aggregate' => 'products',
    'pipeline' => [    
        ['$match' =>  [ 'download_Date' => ['$gte' => $batch ]]],
        ['$sort'  => [  
            'download_Date' => 1
    ['$group' => [ 
        '_id' => [ '$cw_product_id', 'batch' => ['$last' => '$download_Date'] ],
        'allowDiskUse' => true, 
        'cursor' => new stdClass, 

Open in new window

The error I receive when running the php script is

PHP Fatal error:  Uncaught MongoDB\Driver\Exception\RuntimeException: Unrecognized expression '$last'

Open in new window

I've pulled it apart and put it back together so many times, a fresh pair of eyes is needed to spot the obvious.  

Thanks in advance,


I have a text file which has multiple json rows in it.

What I need to do is the following:-

1. Read thru the file
2. Select only certain elements not all, remap to a new name for example AuthenticationId could be AuthId
3. Ingest in to MongoDB as JSON

How can this be achieved in Python?

{"AuthenticationId":"997","CommandLine":"C:\\Windows\\system32\\wbem\\wmiprvse.exe -secured -Embedding","ConfigBuild":"1007.3.0005907.1","ConfigStateHash":"3163607488","EffectiveTransmissionClass":"3","Entitlements":"15","ImageFileName":"\\Device\\HarddiskVolume3\\Windows\\System32\\wbem\\WmiPrvSE.exe","ImageSubsystem":"2","IntegrityLevel":"16384","MD5HashData":"1df2fc82b861bc9612657d1661e9ae33","ParentAuthenticationId":"997","ParentProcessId":"1627804482161","ProcessCreateFlags":"16","ProcessEndTime":"","ProcessParameterFlags":"24577","ProcessStartTime":"1512962460","ProcessSxsFlags":"64","RawProcessId":"9276","SHA1HashData":"1aa3fda50123dd14a055b4d6601beedead69fe11","SHA256HashData":"835f2a94e47830b06654e484bf7a1cc0b9882f579716dca198e32d22218a07e5","SourceProcessId":"1627804482161","SourceThreadId":"39913451443946","TargetProcessId":"1756187997441","TokenType":"2","UserSid":"S-1-5-19","aid":"2bc82f8878df4b9f7712273e755a93be","aip":"","cid":"99cdff8f89af458d858c3d6b3e312e11","event_platform":"Win","event_simpleName":"ProcessRollup2","id":"4ff73eae-de22-11e7-a0dd-06e913674db2","name":"ProcessRollup2V6","timestamp":"1512962460994"}

Open in new window

Open in new window

MongoDB v2.6.12 keeps losing my user credentials on a database. I'm running Iquidus Explorer and thus need to be running v2.6.x of MongoDB for it to work. Most of the time it works fine, but every now and again my script disconnects and gets an error that the user credentials are no longer correct.

To fix this I have to run mongo and type use database1 and then db.createUser( { user: "username", pwd: "blahblah", roles: [ "readWrite" ] } )

This is far from ideal. Can anyone shed any light on what's going on and how to prevent the credentials from getting screwed up?

I'm running MongoDB on CentOS 7 64-bit.
I've been thinking to migrate my erp(java currently) from rdbms(firebird currently) to nosql (mongoDB likely) and i trying to antecipate some issues. I'm trying to make a "failproof" inventory control which never let a qty's item be smaller than 0. Offcourse i still get "ACID bias" which i need to left in order to complete this task. The goal is update inventory qty of all order's items when approve the order. For that, 2 problems can occur which currently are resolved with a trigger.

1.problem: order gets 2 items (ball = qty 2 and chair = qty 1) and there is no enough qty in inventory (ball = qty 1 and chair = qty 0) to complete the order. Once i trigger the command do complete the order, a loop is executed to decrease qty in inventory and fails on the second item cause there is no enough qty. Consequently rollback operation is trigged and everybody go home happy.

2.problem: in one word, concurrency. suppose there is no trigger controling this operation but only "selects and if". User 1 query inventory qtys, see enough qty (ball = 2, chair = 1) e system allow complete the order. While the transaction is running user 2 query same invetory qtys but because first transaction is not complete yet second query see "old" qty (ball = 2, chair = 1) e system also lets complete order. Consequently, 1 qty of chair is descreased twice, but shold be descreased only once and fail on the second. Result: i got negative qty.

I saw some workarrounds with inventory reservation but i …
Created a duplicate username entry in mongoose database and resulted in duplicated error. Now everytime I start server, I get this error:

(node:14839) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CastError: Cast to ObjectId failed for value "{ type: 'Buffer',
  data: [ 89, 243, 30, 231, 66, 69, 45, 56, 123, 65, 153, 72 ] }" at path "_id" for model "users"
(node:14839) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I am trying to update a dict with values searched from mongoDB whose parameters are taken from another dict. What I have till now is:

    lst = {'a':1}
    b={'Name':'name_1', 'Address':'Address_1'}
    lst.update(k:coll.find({"_id":id}{v:1})) for k,v in b.items()

What is the right way to do this procedure?
Hi, I have the following document and I want to delete all keys that are empty:

so it should delete the key year from first instance and build on second instance since is empty. I want the query to update all documents and clear that array of options of empty values.

    _id: 'sldkfjsldkf',
    name: "Red car",
    options: [
          color: "red",
          year: "",
          build: "2000"
          color: "yellow",
          year: "1988",
          build: ""

I just installed ElasticSearch, MongoDB, GrayLog2 but getting an error and unable to access the web interface. Please, suggest any solution r

# ls -lrtha
drwxr-x---.  2 root elasticsearch    6 Apr 24 16:29 scripts
-rwxr-x---.  1 root elasticsearch 2.6K Apr 24 16:04 logging.yml
-rwxr-x---.  1 root elasticsearch 3.2K Jul 20 05:05 elasticsearch.yml


2017-07-20T07:50:36.694Z INFO  [CmdLineTool] Loaded plugin: Elastic Beats Input 2.2.3 []
2017-07-20T07:50:36.696Z INFO  [CmdLineTool] Loaded plugin: Collector 2.2.3 [org.graylog.plugins.collector.CollectorPlugin]
2017-07-20T07:50:36.699Z INFO  [CmdLineTool] Loaded plugin: Enterprise Integration Plugin 2.2.3 [org.graylog.plugins.enterprise_integration.EnterpriseIntegrationPlugin]
2017-07-20T07:50:36.700Z INFO  [CmdLineTool] Loaded plugin: MapWidgetPlugin 2.2.3 []
2017-07-20T07:50:36.708Z INFO  [CmdLineTool] Loaded plugin: Pipeline Processor Plugin 2.2.3 [org.graylog.plugins.pipelineprocessor.ProcessorPlugin]
2017-07-20T07:50:36.709Z INFO  [CmdLineTool] Loaded plugin: Anonymous Usage Statistics 2.2.3 [org.graylog.plugins.usagestatistics.UsageStatsPlugin]
2017-07-20T07:50:36.813Z ERROR [CmdLineTool] Invalid configuration
com.github.joschi.jadconfig.ValidationException: Cannot read file elasticsearch_config_file at path /etc/elasticsearch/elasticsearch.yml. Please specify the correct …

Please bear with me, my Mongo knowledge is minimal and my google foo has failed me after an hour or two.

I have data in Mongo that looks as follows:

    "_id" : ObjectId("xxxx"),
    "applicationData" : {
        "groups" : [
        "status" : "ok"
    "appid" : "UID0001",

    "_id" : ObjectId("yyyy"),
    "applicationData" : {
        "groups" : [
        "status" : "ok"
    "appid" : "UID0001",

From this I'm wanting to group by the content of "groups" and the appid an get a count - the result would be as follows:

group1  UID0001 1
group2  UID0001 2

One step further would be that I'd only like it to report where the "count" is greater than 1

How can I achieve this?

I guess, in SQL, it would be:

select groups, appid, count(*) from db having count(*) > 1

I'm not having much (any) success, further complicated with one of the values I'm wanting to group by is in an Array.

Thanks in advance
The IT Degree for Career Advancement
The IT Degree for Career Advancement

Earn your B.S. in Network Operations and Security and become a network and IT security expert. This WGU degree program curriculum was designed with tech-savvy, self-motivated students in mind – allowing you to use your technical expertise, to address real-world business problems.

I am using php and mongoDb. I am new to mongoDb, but fine with php.  In my mongoDb database I have a  collection called 'users' with a number of fields such as firstname, lastname etc. There are a number of users.

I also have a field/collection in some users called web_links which contains an array.
ie: within my users document:
    "_id" : ObjectId("587af11ec09cf31a1955ed92"),
    "username" : "mike",
    "firstname" : "Mike",
    "lastname" : "Tester",
    "email" : "",
    "web_links" : [
            "name" : "google",
            "link" : "",
            "status" : "1",
            "added" : ISODate("1970-01-18T08:00:57.600Z")
            "name" : "yahoo",
            "link" : "",
            "status" : "1",
            "added" : ISODate("1970-01-18T08:00:57.600Z")

I am trying to firstly update the status of an array item.
I have got as far as this ->

$name = 'google';
$newstatus = '0';

$this->database->users->updateOne(['_id'=>new MongoDB\BSON\ObjectId($userid)],[''=>$name],['$set'=>['web_links.$.status'=>$newstatus]]);

This is returning the following error via firebug:
Uncaught exception 'MongoDB\Exception\InvalidArgumentException' with message 'First
 key in $update argument is not an update operator'.

I have tried to change $set to $push, but that is not the answer.

I would be very grateful for assistance …
I have a SP in which i need to add one condition to check multiple databases by using sys.dm_database_encryption_keys table. 

when encryption_state is 2 and percentage_completed is 0 in the results it should print. Below is my query

DECLARE @Test varchar(10)
SELECT @Test = Database_ID from 
WHERE Encryption_state = 2 and complete_percentage = 0
If (@test not NULL)

If i have multiple DB's which meets the about. It should PRINT multiple ALTER statements with DB Names
My data:

Gage_number Latitude    Longitude   Date    Gage_1  Gage_2  Gage_3

1   35.02   -80.84  1/1/2002    0.23    0   0.7
2   35.03   -81.04  1/2/2002    0   0   0.2
3   35.06   -80.81  1/3/2002    3.2 2.1 0.1
This is just a subset of data. I around 50 gauge stations. I want to find spatial auto correction between my gauge stations for rain fall. Based on distance between them. I have created my distance matrix. But I don’t want to use any library in R. I want to do all steps in a function.

loc <- read.table("rain_data.txt",header=TRUE,fill=TRUE)  
gauge.dists <- as.matrix(dist(cbind(loc$Latitude, loc$Latitude))) #distance matrix
Now since distance between gauges is not uniform. I want to use a certain bin size to decide about distance lags.


If the distance between guage pair 1-2 is 1 meter then assign a distance lag of 1 and so on So Lag 1=intergage dist=1 meter. So Lag 5=intergage dist=5 meter After creating that matrix I will find autocorrelation between gauge pairs.

so for lag 1 intergage dist=1 for lag 5 intergage dist=5

Gage pair   date    RainA   RainB       Gage pair   date    RainA   RainB

1-2 1/1/2002    0.23    0       1-3 1/1/2002    0.23    0.7
1-2 1/2/2002    0   0       1-3 1/2/2002    0   0.2
1-2 1/3/2002    3.2 2.1     1-3 1/3/2002    3.2 0.1
I have a hard time translating it into loop or a function. Any ideas?
Using Database 11g Release 2

When I run the following pl/sql script :

  FOR comp IN (SELECT val FROM productTable@remote_link2 WHERE PRODUCT_ID = 1111)

I get the error :
ORA-06550: line 2, column 34:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 2, column 16:
PL/SQL: SQL Statement ignored
ORA-06550: line 4, column 26:
PLS-00364: loop index variable 'COMP' use is invalid
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.

But when I run as pl/sql only the select statement in the for loop :
SELECT val FROM productTable@remote_link2 WHERE PRODUCT_ID = 1111;
I get the results.

Is the database link not compiling properly in a for loop?
I am working on the vehicle details normalization but I am not sure it is correct or not. could you check it for me please? -we have: vehicle make, manufacturer, model, colour, type, fuel, year and safety.
I have no idea about year and safety . Thanks for your help.

manufactures(manufactur_id, manufactur_name, manufactur_address, manufactur_website)

vehicle_model(model_id, model_name, manufactur_id(fk))





vehicle(vehicle_id, colour_id(fk), model_id(fk), fuel_id(fk), type_id(fk), ......)
I have this reporting project that involves 3 data sources, 2 of the 3 data sources are structured data (SQL Server and Oracle), the 3rd data source is flat files by which I have do lots of parsing, so the question is, how would you approach such project? How would you deal with the flat files, I have my own thoughts but I'm interested in your thoughts on the matter.

Many thanks
Hello I have query to clacultae the balacy of customers in my SQL
I want   The Previous Balance to be added to current transaction
Result would look like :  Balance = Sale+Hadnling+Freight+PreviousBalance  .
This is My query:


jklnzhang.SaleAmount + jklnzhang.Handling+jklnzhang.Freight+ifnull(totaldepnsebycalno.Depense,0) AS Balance,
CustomerBalance.Balance AS Reall,
jklnzhang.dasuanzhanghao AS CBM,
jklnzhang.SaleAmount + jklnzhang.Handling+jklnzhang.Freight+ifnull(totaldepnsebycalno.Depense,0)  -IFNULL(TransfertTotalByCalNo.IcomeAmount,0) AS OtherThing
FROM jklnzhang
LEFT OUTER JOIN CustomerBalance ON jklnzhang.Customer = CustomerBalance.CustId
LEFT OUTER JOIN TransfertTotalByCalNo ON jklnzhang.CalNo = TransfertTotalByCalNo.CalNo
LEFT OUTER JOIN totaldepnsebycalno ON jklnzhang.CalNo = totaldepnsebycalno.CalNo
ORDER BY jklnzhang.Customer
Where can I buy or find an open source for  icd 10 complete database that  has the includes and excludes table mapped to diagnosis codes and check for conflicts on each code pair.
I heard that replication (master slave) can help minimize outages due to heavy schema changes, yet I'm not sure I fully understand that!
1-Do we run changes on the slave then promote that slave to master? If so how is it possible to write to master?
2-what are the cases where replication can help with avoiding or minimizing outage?
Hi All,

I would like to get the gaps between date range and needed it to separate the gaps by MM ID.

could you please someone help me to resolve below in Netezza


ID | MM Number | From | To
12345|4444444 |2015-01-03 |2015-02-02
12346|4444444 |2015-02-03 |2015-03-02

<< missing one record ( ex same MM Number no record for period from 2015-03-03 to 2015-04-02

12347|4444444 |2015-04-03 |2015-05-01
12348|4444444 |2015-05-02 |2015-06-01
12349|4444444 |2015-06-02 |2015-07-01
12310|4444444 |2015-07-02 |2015-07-31

<< missing one record (ex: same MM Number no record for period from 2015-08-01 to 2015-08-31


Expected Out put:
MM No | Missing Start Date | Missing To Date
4444444 |2015-03-03 |2015-04-02
4444444 |2015-08-01 |2015-08-31

I've a table with below data

create table icr_tmp

insert into icr_tmp

insert into icr_tmp

insert into icr_tmp

insert into icr_tmp

insert into icr_tmp

insert into icr_tmp

insert into icr_tmp
My collection contain name attribute, which contains list of brand names.

db.brand.find({'name':{'$regex' : '^Apple?$', '$options' : 'i'}})

Open in new window

This query returns the Brand name 'Apple', but the fact ^ and $ is mentioned, shouldnt return the name 'Apple'. I.e., 'Apple' is not equal to 'Apple?'

Please let me know if we have any option in $regex to solve this ?






MongoDB (from humongous) is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas. MongoDB is developed by MongoDB Inc. and is free and open-source, published under a combination of the GNU Affero General Public License and the Apache License.

Top Experts In