loopbackio / loopback-connector-cloudant Goto Github PK
View Code? Open in Web Editor NEWLoopBack Connector for IBM Cloudant
License: Other
LoopBack Connector for IBM Cloudant
License: Other
Hey, I'm trying to connect my Loopback application to Cloudant but I am not having much luck. I used the slc loopback:datasource
command to add a Cloudant datasource, however, when I start my application I get:
chriss-mbp:project chrisyoung$ npm start
> [email protected] start project
> node server/server.js
project/node_modules/loopback/lib/application.js:238
throw err;
^
TypeError: Cannot create data source "cloudant": Cannot initialize connector "cloudant": Cannot set property 'use' of undefined
at Cloudant (project/node_modules/loopback-connector-cloudant/node_modules/cloudant/cloudant.js:128:26)
at new Cloudant (project/node_modules/loopback-connector-cloudant/lib/cloudant.js:52:19)
at Object.exports.initialize (project/node_modules/loopback-connector-cloudant/lib/cloudant.js:21:18)
at DataSource.setup (project/node_modules/loopback-datasource-juggler/lib/datasource.js:338:19)
at new DataSource (project/node_modules/loopback-datasource-juggler/lib/datasource.js:114:8)
at Registry.createDataSource (project/node_modules/loopback/lib/registry.js:349:12)
at dataSourcesFromConfig (project/node_modules/loopback/lib/application.js:430:19)
at EventEmitter.app.dataSource (project/node_modules/loopback/lib/application.js:228:14)
at project/node_modules/loopback-boot/lib/executor.js:178:9
at project/node_modules/loopback-boot/lib/executor.js:269:5
Here are the dependencies in my package.json
:
"dependencies": {
"cfenv": "^1.0.3",
"compression": "^1.6.2",
"cors": "^2.7.1",
"loopback": "^2.28.0",
"loopback-boot": "^2.18.1",
"loopback-component-explorer": "^2.5.0",
"loopback-connector-cloudant": "^1.0.11",
"loopback-datasource-juggler": "^2.46.0",
"morgan": "^1.7.0",
"newrelic": "^1.28.0",
"serve-favicon": "^2.3.0",
"winston": "^2.2.0",
"winston-loggly": "^1.3.1"
}
And my datasources.json
:
{
"db": {
"name": "db",
"connector": "memory"
},
"cloudant": {
"url": "https://xyz.cloudant.com/apih-tk",
"database": "project",
"username": "username",
"password": "******",
"name": "cloudant",
"connector": "cloudant"
}
}
Any suggestions on what the issue might be or if I might have an incorrect version of packages?
Connector assumes that username and cloudant url subdomain is same. But I do not have to use the admin credentials with full access.
I should be able to create a restricted user for connection through cloudant dashboard and that can also be used by the connector.
Right now this causes an invalid url error because it just copies username as subdomain.
Create a permission for a new user with just read and write access and try adding datasource with these credentials.
Datasource should be connected to cloudant without any errors.
Throws invalid url error.
I tried this with [email protected] and [email protected]
Add the ability to have the cloudant use a proxy agent. Originally raised by pr #53
I'm making a query through the Cloudant connector with a filter that looks like this:
{where: {name: {regexp: '/Foo/i'}}}
I've narrowed down the problem to the following lines: (Starts at 329, for me, in cloudant.js.)
if (cond.constructor.name === 'RegExp') {
if (cond.global)
console.warn('Cloudant regex syntax does not support global');
query[k] = {$regex: cond.source};
} else {
query[k] = {$regex: cond};
}
At the start of the code, my cond
object is as follows:
{
"global": false,
"ignoreCase": true,
"multiline": false,
"source": "Foo"
}
As a RegExp object, it drops into the first if and builds the query with
query[k] = {$regex: cond.source}
and thus ignores the ignoreCase and multiline flags.
I'll submit a pull request shortly with a fix.
Related to strongloop/loopback#517 (comment)
cloudant sort needs specified fieldType, either :string or :number, details please check https://docs.cloudant.com/cloudant_query.html#sort-syntax
Now we already append the fieldType for first level properties but not nested ones. Therefore when sorting with nested property(e.g. test in juggler), cloudant complains
Unspecified or ambiguous sort type. Try appending :number or :string to the sort field. address.city
See #34 (comment)
and #34 (review)
Couch connector supports to query the view, will cloudant connector support this feature?
https://www.npmjs.com/package/loopback-connector-couch
Hi,
According to this link, the updateAll function of the connector should now return an object like:
{ count: <numberOfRecordsUpdated> }
Could you please make the change?
Thanks
Attempting to insert a record into Cloudant with a numeric ID will fail, since the inserted object does not have an id of type String.
Investigate whether or not calling .toString()
on the _id
parameter before an insert request is made will fix the issue.
Reproduce:
slc loopback
, use notes
template, so it has auth system and User
modeluser
instanceInvestigation:
setTimeout in boot script like the following code, give cloudant enough time to migrate model before creating user instance, problem solved.
'use strict';
module.exports = function(server) {
var User = server.models.User;
var doCreate = function() {
User.create({username: 'John', email: '[email protected]', password: 'opensesame'}, function(err, users) {
if (err) console.log(err);
console.log(users);
});
};
setTimeout(doCreate, 5000);
};
Reason
When create a new user, in validation function(juggler/lib/validation.js), it checks uniqueness first, therefore calls find()
, which returns 500 error due to model migration not done
replaceById
and replaceOrCreate
need to be added for loopback-connector-cloudant
Let's take an example:
{
"name": "Person",
"base": "PersistedModel",
"strict": false,
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "name",
"required": true
},
},
"validations": [],
"relations": {
"vehicle": {
"type": "hasOne",
"model": "Vehicle"
}
}
"acls": [],
"methods": {}
}
{
"name": "Vehicle",
"base": "PersistedModel",
"strict": false,
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"brand": {
"type": "string",
"required": true
},
"name": {
"type": "string",
"required": true
},
},
"validations": [],
"relations": {
"owner": {
"type": "belongsTo",
"model": "Person"
}
},
"acls": [],
"methods": {}
}
Is there any way to fetch with a simple query/filter, all the persons who have a vehicle of brand XXX ?
Cloudant in Bluemix has plans with rate limits. It used to have a "Shared" plan with a limit of storage but the new plans have introduced read and write per second limits:
https://www.ibm.com/blogs/bluemix/2016/09/new-cloudant-lite-standard-plans-are-live-in-bluemix-public/
The Cloudant nodejs package has been updated to cope with the new limits and automatically retry. This is implemented with a Cloudant "retry" plugin:
https://github.com/cloudant/nodejs-cloudant#request-plugins
The loopback-connnector-cloudant should be updated to use the latest Cloudant nodejs package and support the configuration of the retry plugin.
Typically I'm getting http error 429 (the Cloudant error code when you reach the rate limit) and messages like:
Error: You've exceeded your current limit of 5 requests per second for query class. Please try later.
at Request._callback (/Users/fred/dev/api/node_modules/nano/lib/nano.js:248:15)
at Request.self.callback (/Users/fred/dev/api/node_modules/request/request.js:187:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/Users/fred/dev/api/node_modules/request/request.js:1044:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (/Users/fred/dev/api/node_modules/request/request.js:965:12)
at emitNone (events.js:91:20)
Hi!
It would be very convenient to get support for CouchDB Design Functions (Map, Reduce...) in the loopback-connector-cloudant. Design Functions are core to CouchDB, and supporting them, will e.g. make it easier to switch between local CouchDB database, and Cloudant database in the cloud.
CouchDB documentation on Design Functions:
http://docs.couchdb.org/en/1.6.1/couchapp/ddocs.html?highlight=map%20reduce
With best regards
-jo2
Currently when attempting to do a createOrReplace or any other replace command through my API, I am receiving a 500 error code:
"error": {
"statusCode": 500,
"name": "Error",
"message": "The connector cloudant does not support replaceById operation. This is not a bug in LoopBack. Please contact the authors of the connector, preferably via GitHub issues.",
"stack": "Error: The connector cloudant does not support replaceById operation. This is not a bug in LoopBack. Please contact the authors of the connector, preferably via GitHub issues. ...
I am posting this here wondering if there is a solution to this or if there is a work around available.
Node v6.9.4
Loopback v3.10.10
looopback-connector-cloudant v1.0.6
When running any queries with a include filter the relation data returned is empty. While in debug mode I was able to get back the following error:
error": {
"name": "Error",
"status": 500,
"message": "function_clause",
"error": "function_clause",
"reason": null,
"ref": 1612317691,
"scope": "couch",
"statusCode": 500,
"request":
{
"method": "post",
"headers":
{
"content-type": "application/json",
"accept": "application/json"
},
"uri": "https://XXXXXX:[email protected]/jenkins/_find",
"body": "{\"selector\":{\"loopback__model__name\":\"LicenseFile\",\"packageId\":{\"$in\":[]}},\"use_index\":[\"lb-index-ddoc-LicenseFile\",\"lb-index-LicenseFile\"],\"sort\":[{\"id:string\":\"asc\"}]}"
}
My Package model hasMany LicenseFiles.
Hi ,
Application is crashing frequently because of the following error. (loopback-connector-cloudant 1.0.11 ).
ERR /home/vcap/app/node_modules/loopback-connector-cloudant/lib/cloudant.js:230
2017-01-16T15:38:39.42+0530 [App/0] ERR for (var i = 0; i < docs.length; i++) {
2017-01-16T15:38:39.42+0530 [App/0] ERR ^
2017-01-16T15:38:39.42+0530 [App/0] ERR TypeError: Cannot read property 'length' of undefined
2017-01-16T15:38:39.42+0530 [App/0] ERR at include (/home/vcap/app/node_modules/loopback-connector-cloudant/lib/cloudant.js:230:31)
2017-01-16T15:38:39.42+0530 [App/0] ERR at Request._callback (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/cloudant-nano/lib/nano.js:216:16)
2017-01-16T15:38:39.42+0530 [App/0] ERR at Request.self.callback (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/request/request.js:186:22)
2017-01-16T15:38:39.42+0530 [App/0] ERR at emitTwo (events.js:87:13)
2017-01-16T15:38:39.42+0530 [App/0] ERR at Request.emit (events.js:172:7)
2017-01-16T15:38:39.42+0530 [App/0] ERR at emitOne (events.js:77:13)
2017-01-16T15:38:39.42+0530 [App/0] ERR at Request.emit (events.js:169:7)
2017-01-16T15:38:39.42+0530 [App/0] ERR at IncomingMessage. (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/request/request.js:980:12)
2017-01-16T15:38:39.42+0530 [App/0] ERR at IncomingMessage.g (events.js:260:16)
2017-01-16T15:38:39.42+0530 [App/0] ERR at emitNone (events.js:72:20)
2017-01-16T15:38:39.42+0530 [App/0] ERR at endReadableNT (_stream_readable.js:923:12)
2017-01-16T15:38:39.42+0530 [App/0] ERR at /home/vcap/app/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31
2017-01-16T15:38:39.42+0530 [App/0] ERR at nextTickCallbackWith2Args (node.js:458:9)
2017-01-16T15:38:39.42+0530 [App/0] ERR at process._tickDomainCallback (node.js:413:17)
2017-01-16T15:38:39.42+0530 [App/0] ERR at process.fallback (/home/vcap/app/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/index.js:482:15)
Could you please help
Hi,
When using the latest release 1.1.0, seems like attempting an upsert of an instance that is not yet in the database gives a 404.
Reverting to 1.0.11 fix the issue.
Could you please take a look?
Thanks
Hi,
Not sure this is really an issue, maybe I just don't know the right way of doing things...
Let's take the following example with two models Person and Vehicle:
{
"name": "Person",
"base": "PersistedModel",
"strict": false,
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "name",
"required": true
},
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
{
"name": "Vehicle",
"base": "PersistedModel",
"strict": false,
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
},
"validations": [],
"relations": {
"owner": {
"type": "belongsTo",
"model": "Person"
},
},
"acls": [],
"methods": {}
}
Is there any simple query to perform in order to fetch all vehicles that don't have an owner?
Would it be possible to do anything like one of the lines below?
Vehicle.find({where: {personId: null}})
Vehicle.find({where: {personId: undefined}})
Vehicle.find({where: {owner: {exist:false}}})
Until I manually created the database in Cloudant, I got this error:
Error: Database does not exist
Cloudant supports the generation of API keys with their own credentials, which ensures that you're not using administrative credentials to perform operations against the DB.
The nodejs-cloudant driver allows use of keys, and this connector should do the same.
Hi.
I tried found at cloudant data, but could not found minus value data.
success: lat = 90
failed: lat = -90
How to find the minus value data ?
source: --databasename--.js
.
--databasename--.find({"where":{"and":[{"lat":-90}]}},function(err, result) {
if (err) {
console.log("--- error ---";
} else {
console.log("--- lng: ", result.lng);
}
}
.
model.properties: --databasename--.json
.
"properties": {
"_id": {
"type": "string",
"id": 1
},
"_rev": {
"type": "string"
},
"timestamp": {
"type": "date"
},
"lat": {
"type": "number"
}
}
.
cloudant data:
{
"_id": "{any_id}",
"_rev": "{any_rev}",
"timestamp": "2016-05-12T06:00:00Z",
"lat": -90
"lng": 130
}
,
{
"_id": "{any_id}",
"_rev": "{any_rev}",
"timestamp": "2016-05-12T06:00:00Z",
"lat": 90
"lng": 135
}
I tried in cloudant query box , but also could not found.
query:
{
"selector": {
"loopback__model__name": "--databacename--",
"lat": -90
},
"fields": ["_id", "_rev", "lat", "lng" ]
}
I have documents with _id,Status and dateUploaded fields. I want to update the document where Status is Available and has minimum date.
I am able to successfully run the below code, but it updates all the documents where the Status is 'Available'
orm.TEST.updateAll({Status: 'Available'}, {Status: 'Blocked'}, function(err, result) {
console.log(err + " "+result);
});
The logic I am trying to execute is
orm.TEST.updateAll( {Status: ‘Available’, dateUploaded: logic for min date}, {Status: ‘Blocked’}, function(err, results) {
return callback(err, results);
});
How to get the minimum date in the where clause ?
I define my own id which is string. When I want to get using the get (id) the result is error :
{
"error": {
"name": "Error",
"status": 404,
"message": "could not find a model with id 1",
"statusCode": 404,
"code": "MODEL_NOT_FOUND",
}
}
Same can be happen if I use put(id). But when I only use get, it is works normally.
But when I store the id as full string, i get the result
{
"name": "Record",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"sharedKey": {
"type": "string",
"description": "Unique ID",
"required": true
}
...
},
...
}
GET https://myhost/api/Records
[
{
"sharedKey":"12345",
"id":"0266cb32b2afd1d6ea7760ab54981f49",
"_rev":"2-4cb556a75312172c7730ecbdafb1cd1e"
},
{
"sharedKey":"aString",
"id":"33c6ca3d10aff422f697322bd1cfddab",
"_rev":"2-ff30b9a96e4aba1ae36cca785baad2e5"
}
]
GET https://myhost/api/Records?filter[where][sharedKey]=aString
[
{
"sharedKey":"aString",
"id":"33c6ca3d10aff422f697322bd1cfddab",
"_rev":"2-ff30b9a96e4aba1ae36cca785baad2e5"
}
]
GET https://myhost/api/Records?filter[where][sharedKey]=123456
[]
A customer wrote into support with the following issue:
Using APIC, I create a loopback relation from two models, Item and Review. Item has three fields (id:string, name:string and desc:string). Review has three fields (reviewer: string, reviewDate: date and review:string). All three fields are required. For my relationship, Item has many Reviews. I should also mention that I am using a Cloudant datasource for this scenario. I then go to "Explore" and I use Post to create an Item. So far everything is fine. Then, I go to create a "Review" for my Item, here is where things get a little sticky. First I enter a PersistedModel id for the Item that I want to Post a review for. Then I click the Generate link to generate the data for the review. When I do this however, under data the only thing that gets generated is "" (versus the JSON object that I expect). If I change my Review model where the reviewDate field is not required, then I see a JSON object displayed, although the behavior still appears to be flaky at times. I believe there is a problem with the Explore generate data option.
When updateAll()
is invoked with loopback model
instance as payload, it fails with complaining: Bad special document member: __cachedRelations
and similar.
Other NoSQL connector i.e. mongo connector, AFAIK, supports model
instance as payload.
connected to #56
The options object we expect at connector construction is not being handled in a way that allows
configuration options to be passed through to the Cloudant driver (see
https://github.com/strongloop/loopback-connector-cloudant/blob/master/lib/cloudant.js#L56).
We should only minimally inspect the options object for the correct parameters and format (to ensure that they've provided credentials), but otherwise should not prevent this pass-through.
BUG
db.define()
to create modeldb.automigrate()
The fix in #3 allowed queries to return results > 200 from the connector. However, now I am getting a "too many boolean clauses" error when returning my results.
Context: I am running two queries. The first finds the total count of a particular package model (2k+ results). This returns fine without any problems. My second query has a include filter to tie in another relation to the package instances and this is where I get the error. It looks like the problem is with the query containing a $in field of the array of package ids which is over the boolean clauses limit.
Further looking at the code in lib/cloudant.js it looks like the include query is ran on the total docs returned. Would running the include query on each 200 page bookmark solve this issue?
@tonyffrench your thoughts? Also thanks for all the help in the previous issue!
$elemMatch: Matches and returns all documents that contain an array field with at least one element that matches all the specified query criteria.
Use case:
seed data
{
seq: 0,
name: 'John Lennon',
friends: [
{name: 'Paul McCartney'},
{name: 'George Harrison'},
{name: 'Ringo Starr'},
],
},
wrong query
{where: {friends.name: 'Ringo Starr'}}
right query
{where: {friends: {$elemMatch: {name: 'Ringo Starr'}}}}
steps to reproduce:
1.npm install -g strongloop-connector-cloudant
2.mkdir testLoopbackconnectorcloudant
3.cd testLoopbackconnectorcloudant
4.slc loopback
5.slc loopback:datasource
strongbot@plnx133:~/testLoopbackconnectorcloudant> slc loopback:datasource
? Enter the data-source name: cloudantdb
? Select the connector for cloudantdb: IBM Cloudant DB (supported by StrongLoop)
Then create model
slc loopback:model
strongbot@plnx133:~/testLoopbackconnectorcloudant> slc loopback:model
? Enter the model name: cloudantmodel
? Select the data-source to attach cloudantmodel to: cloudantdb (cloudant)
? Select model's base class Model
? Expose cloudantmodel via the REST API? Yes
? Custom plural form (used to build REST URL):
? Common model or server only? server
Afterwards,
in the datasources.json
you will see the following:
I am not sure why the db with memory connector is there. I never selected it and only
selected cloudant connector
"db":
"name": "db",
"connector": "memory"
},
"cloudant": {
"name": "cloudant",
"connector": "cloudant"
}
git checkout loopback-2.x
# refresh node_modules
npm test
Now we commented all test cases to get CI pass in https://github.com/strongloop/loopback-connector-cloudant/pull/29/files, but after CI config done we need to bring them back and make them pass all required platforms.
Reproduce:
Create a model Test
Create an instance for Test
:
testInstance: {
id: 1,
name: 'test1'
skills: [
{id: 0, text: "JAVA"},
{id: 1, text: "CSS"},
{id: 2, text: "HTML" },
{id: 3, text: "JAVASCRIPT"},
{id: 4, text: ".NET"}
]
}
Try updateAll:
Test.updateAll({id: test.id}, {skills: [
{ id: 1, text: "newJAVA"},
{ id: 2, text: "newCSS"}
]}, function(err, count){} );
The updated skills are expected to be:
skills: [
{ id: 1, text: "newJAVA"},
{ id: 2, text: "newCSS"}
]
But actual result is:
skills: [
{id: 0, text: "newJAVA"},
{id: 1, text: "newCSS"},
{id: 2, text: "HTML" },
{id: 3, text: "JAVASCRIPT"},
{id: 4, text: ".NET"}
]
I get the following error when calling a _find with regex via my loopback application. When using the in-memory database instead of Cloudant everything works fine.
Regards Helmut
_datasource:node_logs:1457390961693, source:node-js-console, _writetime:06/14/16 19:21:41:821 +0000, severity:I
datetime=2016-06-14T19:21:33.787 +0000,,message=[2016-06-14 19:21:33.786] [ERROR] console - { [Error: Invalid operator: $regex]
name: 'Error',
error: 'invalid_operator',
reason: 'Invalid operator: $regex',
scope: 'couch',
statusCode: 400,
request:
{ method: 'post',
headers:
{ 'content-type': 'application/json',
accept: 'application/json' },
uri: 'https://XXXXXX:[email protected]/n-odata-server-example-db/_find">https://XXXXXX:[email protected]/n-odata-server-example-db/_find',
body: '{"selector":{"loopback__model__name":"BusinessTrip","Location":{"$regex":{}}},"use_index":["lb-index-ddoc-BusinessTrip","lb-index-BusinessTrip"],"limit":20,"sort":[{"Starttime:string":"desc"}]}' },
headers:
{ 'x-couch-request-id': '71dff32505',
date: 'Tue, 14 Jun 2016 19:21:33 GMT',
'content-type': 'application/json',
connection: 'close',
'cache-control': 'must-revalidate',
'strict-transport-security': 'max-age=31536000',
'x-content-type-options': 'nosniff;',
statusCode: 400,
uri: 'https://XXXXXX:[email protected]/n-odata-server-example-db/_find' },
errid: 'non_200',
description: 'couch returned 400' }
Error: Invalid operator: $regex
at Request._callback (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/nano/lib/nano.js:248:15)
at Request.self.callback (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/nano/node_modules/request/request.js:200:22)
at emitTwo (events.js:87:13)
at Request.emit (events.js:172:7)
at Request.<anonymous> (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/nano/node_modules/request/request.js:1067:10)
at emitOne (events.js:82:20)
at Request.emit (events.js:169:7)
at IncomingMessage.<anonymous> (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/nano/node_modules/request/request.js:988:12)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
,source=node-js-console,severity=I
When given an array as input for a field, we are getting TypeError k.match is not a function.
We cannot give primary id as where clause in input parameter.
Both the issues are for updateAll method
#Same problem as updateAll
: #44
Reproduce:
A model instance with an array type property
modelInstance: {
name: 'test',
arrProperty: [
{id: 1, name: original1},
{id: 2, name: original2},
{id: 3, name: original3}
]
}
When do updateAttributes:
modelInstance.updateAttributes({arrProperty: [
{id: 1, name: new1},
]})
The expected new arrProperty is
arrProperty: [{id: 1, name: new1}]
But actual result is
arrProperty: [
{id: 1, name: new1},
{id: 2, name: original2},
{id: 3, name: original3}
]
From cloudant document page: https://docs.cloudant.com/cloudant_query.html#sort-syntax
You cannot use combination or array logical operators such as $regex as the basis of a query when using indexes of type json. Only equality operators such as $eq, $gt, $gte, $lt, and $lte (but not $ne) can be used as the basis of a query for json indexes.
{
"selector": {
"afieldname": {
"$regex": "^A"
}
}
}
would result in error error: "no_usable_index", reason: "There is no operator in this selector can used with an index."
A solution is to use an equality operator as the basis of the query. You can add a ‘null’ or always true expression as the basis of the query. For example, you could first test that the document has an _id value:
"_id": { "$gt": null }
This expression is always true, enabling the remainder of the selector expression to be applied.
So build selector like:
{
"selector": {
"_id": {
"$gt": null
},
"afieldname": {
"$regex": "^A"
}
}
}
When using a model and using the method replaceById, it returns the following errror:
Error: The connector cloudant does not support replaceById operation. This is not a bug in LoopBack. Please contact the authors of the connector, preferably via GitHub issues.
at Function.DataAccessObject.replaceById (C:\secret_path_to_my_nodejsapplication\node_modules\loopback-datasource-juggler\lib\dao.js:2818:15)
at C:\secret_path_to_my_nodejsapplication\app.js:255:8
at Layer.handle as handle_request
at next (C:\secret_path_to_my_nodejsapplication\node_modules\express\lib\router\route.js:131:13)
at Route.dispatch (C:\secret_path_to_my_nodejsapplication\node_modules\express\lib\router\route.js:112:3)
at Layer.handle as handle_request
at C:\secret_path_to_my_nodejsapplication\node_modules\express\lib\router\index.js:277:22
at Function.process_params (C:\secret_path_to_my_nodejsapplication\node_modules\express\lib\router\index.js:330:12)
at next (C:\secret_path_to_my_nodejsapplication\node_modules\express\lib\router\index.js:271:10)
at C:\secret_path_to_my_nodejs_application\app.js:64:3"
The error declares that i have to contact the authors via github issues, so here i am!
Hi,
Our loopback APIs with DB queries have been working fine until all of a sudden, APIs involve one particular type of model stops working and always returns "Error performing text search".
e.g. APIs using this query:
{"selector":{"loopback__model__name":"package","_id":"bd3728cc668db9d363f0b0d98c448c96"},"use_index":["lb-index-ddoc-package","lb-index-package"],"limit":1,"sort":[{"id:string":"asc"}]}
Returns error:
Error performing text search: {timeout, {gen_server,call, [<13537.1556.3932>, {prompt, [<<"index_doc">>, {[{<<"_id">>, <<"fb6e036200e23926d5a1de801592f068">>}, {<<"_rev">>, <<"1-1e219de3b35ba0c9a55802a897cc384e">>}, {<<"name">>,<<"IIBCloud">>}, {<<"version">>,<<"0.0.0">>}, {<<"path">>,<<"iib.cloud.ui.web.war">>}, {<<"scanId">>, <<"cfce92cc5425d21cb65dce09553b0ce3">>}, {<<"license_types">>, [<<"Apache-2.0">>,<<"BSD-2-Clause">>, ... ...
Seems to me trouble with index ["lb-index-ddoc-package","lb-index-package"].
How to validate and fix this? This is impacting our production env. Please advice.
I am using the loopback model find function with the loopback-connector for cloudant. The number of models returned are always <= 200. Upon further investigation I found that this is a limitation imposed by cloudant's query.
https://developer.ibm.com/answers/questions/233525/nodered-cloudant-using-cloudant-node/
https://docs.cloudant.com/cloudant_query.html#finding-documents-using-an-index
The bookmark field is used to for paging through the result sets each of which being a max of 200 rows.
When debugging the Find matching model instances by filter code in lib\cloudant.js it looks like the query results return both a doc and bookmark field. However, the results.doc is the only thing that is callback.
Is there a way to have a filtered query result of greater than 200 or use the bookmark to page through in the current connector implementation?
Parent story see: strongloop/loopback#517
A similar mongodb pr see: loopbackio/loopback-connector-mongodb#301
Use case:
Person
hasMany Vehicle
.
We want to support a filter like
Person.find({
where: {
vehicle.brand : 'D' // second level property
}
})
Trying to query cloudant (findOne) through the connector using regex, but the $regex operator value always gets passed as blank. For instance
MyModel.findOne({where: {myField: {regexp: '10'}}}, function(err, resp) {
console.error('OUTPUT ', err, resp);
});
This gives the below error in console:
{ [Error: Invalid operator: $regex]
name: 'Error',
error: 'invalid_operator',
reason: 'Invalid operator: $regex',
scope: 'couch',
statusCode: 400,...
body: '{"selector":{"loopback__model__name":"MyModel","myField":{"$regex":{}}},"use_index":["xy-index-ddoc-MyModel","xy-index-MyModel"],"limit":1,"sort":[{"id:string":"asc"}]}' },
...
...
After updating to the latest Angular CLI I have been receiving this error everytime that I attempt to send a post or get request to upload/retrieve a document.
I am not clear what property password it is referring to and why this error is occurring after I updated the angular cli.
I am hoping to be able to upload and retrieve documents from my cloudant db
I receive the following error:
"error": {
"name": "TypeError",
"status": 500,
"message": "Cannot read property 'password' of undefined",
"stack": "TypeError: Cannot read property 'password' of undefined\n
}
Noje.js version = 7.7.3
LoopBack version = 2.38.2
A further discussion of #54 (comment)
Regarding
When I step back a bit and look at the problem from a high level perspective, then I think it should be acceptable to require callers of patch/replace operations to provide _rev in the data, as that's the way how CouchDB/Cloudant allows clients to detect and resolve conflicts
Our current implementation:
Now whenever rev
is needed, eg: in function Cloudant.prototype.delete()
, Cloudant.prototype.replaceById()
, we call getCurrentRevision()
.
But considering the nature of Cloudant db, we should ask the caller to provide rev
, and return error if it's missing.
Affected functions:
data: {rev: rev_of_new_data}
data: {rev: rev_of_new_data}
data: {rev: rev_of_new_data}
Use updateAttributes
function to update
a model instance and use update
function in call for updateOrCreate
.
Currently, update
performs a destructive update. With this change update
function should be partial update.
This filter works.
filter = { where:
{ foo: 'foo' }
};
model.find(filter, (err, rslt) => { /* ... */ });
But this doesn't.
filter = { where: { and: [
{ foo: 'foo' },
{ bar: 'bar' }
]}};
model.find(filter, (err, rslt) => { /* ... */ });
When the data-source configuration does not provide all required settings, the connector initialisation fails with AssertionError: url is not valid
. This error message is misleading - it hints that the url
setting is required, which is not true.
Please improve the code building settings for cloundant
driver (source code) to verify that the configuration is valid and report a helpful error message otherwise.
/cc @ritch @raymondfeng
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.