0

Basically what the title says - I've been getting a 404 Not Found on all ids that I enter for "id":

dpd.items.get("id", function(results, error) {
 console.log(results);
});

And a 400 Bad Request on any value of "id":

dpd.items.put("id",{category:value},function(results, error){
 console.log("Record updated");
});

All the id values exist in the Deployd dashboard, and I am able to make get requests using any category parameters OTHER than ID.

Feels like I've tried everything at this point, please help!

2 Answers2

0

Deployd create crud API of any collection.
Make sure collection name is correct try to use
http://localhost:PORT/items/id .. if this will also give 404 then open
http://localhost:PORT/dashboard/items/events/
and On dashboard goto dashboard/items/events/ this will open ON GET panel, write there console.log(this.query)

and about 400 request , you write the code console.log(this.body) on http://localhost:PORT/dashboard/items/events/#put-panel

This is the way to debug your API, deployd have some issue but better framework to create API instantly

Muhammad Ali
  • 1,992
  • 1
  • 13
  • 20
0

This error can occur if you insert documents through a different client than deployd.

From here:

MongoDB uses ObjectIds as the default value for the _id field if the _id field is not specified ... if a client does not add an _id field, mongod will add an _id field that holds an ObjectId.

Although the IDs created by mongoDB are visible in the deployd dashboard, they are not normal strings (like the IDs generated by deployd) and deployd does not find them when it's looking for a string.

Try to run a query like the following with any other mongoDB client (e.g. Robomongo):

db.yourcollection.find({_id: ObjectId("some_id_you_know_exists_in_collection")})

If it does not throw an error, the id is most likely an ObjectId that was not created by deployd.

Unfortunately, there is no easy fix. (At least not for big collections and complicated apps.) For SMALL collections I'd suggest to just duplicate the data into a new collection and let deployd create new IDs.

Quick, dirty and untested:

dpd.collection.get({}, function(res) {
    _.each(res, function(object){
        object.oldId = object.id //add id backup 
        delete object.id

        // post new object without id -> deployd creates a new id
        dpd.newcollection.post(object, function(res, err) {
            if(err) {
                console.log(err);
            };
            if(res) {
                console.log(res);
            };
        })
    });
})

You have to decide for yourself if that works for you.

docnoe
  • 61
  • 5