Data not returned from custom collection - node.js

I have a hand-made collection (mymodel) in MongoDB. I have created a sails model+controller using 'sails generate api mymodel'
I am now trying to use the sails find() method using the REST api: http://localhost:1377/mymodel, but I do not get any data returned. I have even tried to write my own end-point method and used the Waterline ORM find() method, but still don't get anything returned.
Am I missing something? Is there something more to be done?
Its a simple model, like {A:123,b:"wf"}
No specific data pieces
From mongo shell, I get the complete information

Found the problem.
If a create a collection using the name "MyModel" in MongoDB, and then create a controller+model in sails.js (sails generate api MyModel), sailsjs does not seem to use the "MyModel" collection, but rather tries to create a new collection completely in lower case ("mymodel") where all the transactions are committed.
So the trick is to create a collection in lowercase only so that sails starts using it
Not sure if this is a bug in sails.js

Related

How to load a child component of a relation in Strapi

In my Strapi application, I have the following structure:
Footer(single type) > Section(component) > Menu(collection type) > link(component)
When performing a query Strapi only returns the id of the link and I needed its LABEL and URL, does anyone know how I can bring this in a query only?
Strapi section
Link Component
Footer API return
I used this topic on the Strapi forum, but without success yet
https://forum.strapi.io/t/how-do-i-return-only-selected-fields-from-the-model-and-its-relation/1115/2
Disclaimer; im new to Strapi.
The Strapi get requests only populates with relational data in a single layer of nesting. Your links looks to be on the second layer.
You have two options:
Query for the links by ID from your client after receiving the IDs. This can be done efficiently using Promise.all.
Modify the default GET handler for the ressource in the Strapi code. Extend the query to join on your links, and return the response in its entirity.
Update on option 2;
You can customize the logic behind any single endpoint handler in the API in your Strapi backend. The process is best descriped in their documentation on Custom Data Response's. Note that the syntax on how to query the database is based on a popular ORM depending on your database of choice. The ORMs are:
MongoDB (through Mongoose)
Postgres, MySQL, SQLite3 and more (through Bookshelf)
Redis (through ioredis).

How can i configure Mongoose to automatically create objects in my mongoDB on app start if none is found?

I am coming from a Java Hibernate frameworks, where an sql script can be written and added to a project, with the intentions of creating objects in my Mongo Database when the app runs and no data was found in a specific database table. I am using Mongoose presently with mongoDB, and i want to initialize my mongoDB table with objects if none is found. Initially i achieved this my creating an object and calling the new mongoose.save(obj) inside my app.js which is my start up file. But is there a cleaner way one already supported by Mongoose, or is this my best bet ?

use functions inside of defaultscope in sequelize

I'm using Sequelize for a project with a single db for multiple applications. I need to query MSSQL database for each request based on the application_id I receive in the request. (on Nodejs)
Calling a function inside of scope in Sequelize model definition requires specifying the name of the scope for each query which is not desired.
I think if I could use functions inside of defaultscope to make it work (without manually overriding it again and again) . Or if there's any other way to accomplish this (better without rewriting Sequelize functions). Thank you!

use Waterline as Standalone (no express)

Good Afternoon,
I am new with node.js and I try to develope an only command app.
For this app I need an ORM and I wish to use WATERLINE as standalone but not in express framework.
I looked at the example and I succeed to see my different collections.
// Our collections (i.e. models):
ontology.collections;
console.log(ontology.collections);
// Our connections (i.e. databases):
ontology.connections;
I am stucked after this. I can't find a way to return my models and make queries.
If someone could help me taht would be great.
Thanks
If you initialized Waterline in the ontology variable and got the collections successfully loaded as you say, now you can access each collection loaded (with loadCollection()) like this:
ontology.collection.mycollection
Where mycollection is the identity defined in your model.
Then you can make queries:
ontology.collection.mycollection.find(...)

How to get DB object in SailsJS / Waterline adapter methods?

I am trying to write a SailsJS / Waterline adapter for OrientDB using Oriento module for NodeJS.
I am able to understand the basics of Waterline adapter interface using boilerplate adapter code for SailsJS but not sure how to get hold of DB object in adapter methods. I am sure DB object is created and maintained by SailsJS or Waterline but how to get an access to it in adapter's methods as without DB object, I will not be able to make call to OrientDB. Look for code samples in Oriento module to know how to call OrientDB from NodeJS.
I will appreciate if some one can show some example code of getting DB object in adapter's method - define(), describe(), drop(), find() etc.
We're unfamiliar with Sails, but looks like the _dbPools private variable is what you're looking for - https://github.com/balderdashy/sails-adapter-boilerplate/blob/master/index.js#L59

Resources