0

I tried to create a user & pet model in Many to Many relationship using mongoDB and sailsJS, db creation and loading the data's are just fine i checked in mongoDB for dbs and collection it exists. when i try to get the user list and pet list its showing me the contents but when i try to GET a single pet by its iD under user by his iD i'm not getting result

It shows "Response does not contain any data."

I tried to get PET like this "http://localhost:1337/user/54ffd28e9d9ee93c166c7500/pets/54ffd28e9d9ee93c166c7503"

I also tried to display the pet by its name instead of iD its also not working

my sails version is 0.11.0.. my OS is Win7 64 bit

Anandapriyan S.D
  • 315
  • 4
  • 15
  • Could you please provide the code for your API? Especially for the route that you are trying to access. – vladzam Mar 11 '15 at 13:22
  • https://docs.google.com/document/d/1A9hEHKbxSqIMqyOlkAe3LfO6S5hLL6pG60wUAW8GlTU/edit – Anandapriyan S.D Mar 12 '15 at 08:55
  • Could you please update your post with the source code so that it is readable? It's tiring to read it and format it in the document format that you provided. – vladzam Mar 12 '15 at 09:17
  • @VladZ. i found the solution in git hub.. https://github.com/balderdashy/sails/issues/2658 at this location... now its working – Anandapriyan S.D Mar 14 '15 at 04:09

1 Answers1

0

here's a maybe useful thing to know, when requesting by id while using mongoDB.

to get some document inside of a collection, passing the id through an URL, it is useful to use the const { ObjectId } = require('mongodb').

you can for instance do as following:

// VS code might or might not write this for you
// but if you VIM, you have to write yourself

const { ObjectId } = require('mongodb')

fastify.get('/something/:id', async function (req, reply) {
    const db = await this.mongo.db;
    await db.collection('YourCollection', callbackFunc);

    function callbackFunc(err, col) {
      if (err) reply.send(err)

      col.findOne({ "_id": new ObjectId(req.params.id) }, (err, result) => 
      {
        console.log(result)
      })
    }
  })

Let me know if it helps, best wishes

bessa3301
  • 131
  • 3
  • 5