EzDevInfo.com

mandango

Mandango is a simple, poweful and ultrafast Object Document Mapper (ODM) for PHP and MongoDB.

Removing null objects from json in mongodb

I am using php and MongoDB, the opensource library that i am using makes an auto-generated code to make calls to mongodb. it is sort of an ODM layer.

Now when i am using embedded documents, in the parent document, i have to update the set of embedded documents, the Library makes a call using $unset, which as per Documentation sets the value at index to null and does not remove it.

thus now when i want to replace the embedded document set, i have to first remove($unset) the existing set, and then add new leaving me with the result like this:

Original:
{
    "parentDocument": {
        "parent_id": "1",
        "embeddedDocument": {
            "0": {
                "childValue": "0"
            },
            "1": {
                "childValue": "1"
            },
            "2": {
                "childValue": "2"
            }

        }
    }
}

Updated:

{
    "parentDocument": {
        "parent_id": "1",
        "embeddedDocument": {
            "0": null,
            "1": null,
            "2": {
                "childValue": "2"
            }

        }
    }
}

How can i clean this data from the db..?? I have tried many forums, didnt find any valid solution for the same. I need to clean this complete data. Thanks


Source: (StackOverflow)

MongoWriteConcernException when trying to replace old embedded records with new

I am using mandango framework for PHP MongoDB application. The following the query generated in run time when posting changes to mongodb.

{"$set":{"sort_order":401},"$pushAll":{"Attribute_description":[{"language_id":1,"name":"new Data"}]},"$unset":{"Attribute_description.0":1}}

The problem is that the below issue occurs when this statement is executed:

Fatal error: Uncaught exception 'MongoWriteConcernException' with message 'localhost:27017: Cannot update 'Attribute_description' and 'Attribute_description.0' at the same time'

The actual action is that in the collection attribute, the attribute description is an embedded attribute. while the documentation says the replace functionality should work. some how its giving the exception.

can anyone suggest what should i do so that the command works properly. that is the embedded attribute gets replaced completely.


Source: (StackOverflow)

Advertisements

How to create autoincrement field in Mandango

I'm using in my project mandago ODM for mongodb.

http://mandango.org

I know that in MongoDb you can define JS functions on fields but I don't know how to do it with mandango. I create autoincrement ID field in more clever way than getting last record then incrementing it in PHP and saving in db. So my question is how to create an autoincrement field in mandago ODM?

I'd put some code but there's really nothing to put just pure code classes generated by Mondator.


Source: (StackOverflow)