loopbackjs

Aggregation issue with Mongo 3.6

▼魔方 西西 提交于 2019-12-31 03:33:11
问题 I was using the aggregate function without any problem connecting a 3.4 mongodb. When I change to a 3.6 db, I've got the message: The 'cursor' option is required, except for aggregate with the explain argument. Sorry if it's already posted. I am unable to find any solutions 回答1: In mongo 3.6 there has been changes while using aggregate you have to use cursor, unless you include the explain option, you must specify the cursor option. I faced same error as you were facing. Now you have to do it

Joining two models in loopback using include filter

懵懂的女人 提交于 2019-12-30 11:05:13
问题 I have two models Purchase and Products, and productId is common for both. I need to find the productDetails from product model for a purchaseId. So I have created a custom endpoint in Purchase model, called getProductDetails. This is how I am trying to query the models. Purchase.find({ "filter": { include: { relation: 'Product', scope: { fields: ['productDesc'], } } }, where:{ id:purchaseId }, My relation is Purchase belongsTo Product, foreignKey being productId Product hasMany Purchase But

loopbackjs: Attach a model to different datasources

旧巷老猫 提交于 2019-12-30 04:33:05
问题 I have defined several models that use a Datasource "db" (mysql) for my environment. Is there any way to have several datasources attached to those models, so I would be able to perform REST operations to different databases? i.e: GET /api/Things?ds="db" GET /api/Things?ds="anotherdb" GET /api/Things (will use default ds) 回答1: As @superkhau pointed above, each LoopBack Model can be attached to a single data-source only. You can create (subclass) a new model for each datasource you want to use

MongoDB aggregation on Loopback

和自甴很熟 提交于 2019-12-29 05:30:24
问题 How do I obtain the sum of a Loopback PersistedModel? There does not seem to be a documentation on how to achieve that. If possible I would like to avoid having to find all the rows and sum it in Node.js. UPDATE Trying out the example from https://github.com/strongloop/loopback/issues/890 var bookCollection = Book.getDataSource().connector.collection(Book.modelName); I got an error throw new Error('MongoDB connection is not established'); How do I get a handle on the collection to manually

How do I connect to a fake SMTP server using Loopback

℡╲_俬逩灬. 提交于 2019-12-25 14:45:51
问题 This similar to to this question, but intstead I am trying to connect to this fake smtp-server https://www.npmjs.com/package/smtp-sink I run this server using npm i smtp-sink and smtp-sink and it seems fine Here is how I have configured my datasource: "emailDataSource": { "connector": "mail", "transports": [{ "type": "smtp", "host": "localhost", "secure": false, "port": 1025, "tls": { "rejectUnauthorized": false } }] } and sending the email through an endpoint as such: (this 9is inside a

How do you import a user model with strongloop arc database discovery

孤街醉人 提交于 2019-12-25 04:38:21
问题 The loopback application already comes equipped with a user model and CRUDs; however, I'm trying to hook an old database up to my loopback application that already contains a user model so the model discovery replies with: ValidationError: The `ModelDefinition` instance is not valid. Details: `name` is not unique (value: "User"). at /home/theory/.nvm/versions/v0.12.4/lib/node_modules/strongloop/node_modules/loopback-datasource-juggler/lib/dao.js:264:12 at ModelConstructor.<anonymous> (/home

loopback- how to access from one model to another and send email?

只谈情不闲聊 提交于 2019-12-25 00:06:31
问题 I have the career form where i have all the details with the file attachment. now i can able to store the file. I am able to send email, but both sending email with attachment is not happening because i have two model one is for attachment and the other is Persisted model. In the attachment.js i am able to get the file file name but i could not send email with attachment. Here is code. career.js 'use strict'; const app = require('../../server/server'); module.exports = function(Career) {

upload file and text in loopback

ぐ巨炮叔叔 提交于 2019-12-24 23:32:50
问题 Hello guys i m new too loopback, so don't know if it is possible or not <form> <input type="text" id name="product"> <input type="text" id name="productdesc"> <input type="file" id name="product"> </form> Demo image of form: This demo form i m try to save to database using model rest api (model named as product) Note: just try to save input text field and file path url. i have created a container, using container i can easly upload a file to folder name as storage/file inside server folder.

Loopback: How to add afterRemote of a model to another model

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 19:24:34
问题 I have Notification model which looks like this "use strict"; module.exports = function(Notification) { }; And I have another model which is Post: "use strict"; module.exports = function(Post) { Post.prototype.postLike = function(options, cb) { this.likes.add(options.accessToken.userId); cb(null, "sucess"); }; Post.remoteMethod("postLike", { isStatic: false, accepts: [{ arg: "options", type: "object", http: "optionsFromRequest" }], returns: { arg: "name", type: "string" }, http: { path: "

How to Loopback Remote api response load in react admin datagrid

元气小坏坏 提交于 2019-12-24 08:59:56
问题 i am using loopback 3 developed api load into react admin using react admin loopback package.my doubt is i am write remote api id based get list of values in my response.its result how to load react admin datagrid. This i am try to load into my react admin based on react admin loopback.this standard template id passed to my template page.this id based call the api and load into datagrid.i dont know? how to pass the api in datagrid http://localhost:3000/api/templates