We have a list of URIs and which we need to read in the sequence in which it is passed.
Example1
doc(("/doc1", "/doc2", "/doc3"))
above function should return the content of "/doc1" then "/doc2" and then "/doc3" but it is not happening.
The same thing is happening is with the below query also.
Example2
cts:search(doc(), cts:document-query((("/doc1"),("/doc2"),("/doc3"))))
What will be the solution if I want to read the documents in which sequence I pass the URIs ?
Any help is appreciated..!
cts:search has its own ordering functionality, which you can trigger using functions like cts:index-order. fn:doc takes an array, and will return them in database order. Neither of them sounds like what you are trying to achieve.
I would suggest explicitly iterating over the uris, and fetching the uris one by one. You could use ! operator for this, for instance:
("/doc1", "/doc2", "/doc3") ! doc(.)
HTH!
#grtjn's answer is correct but you could reduce it to one database query and just return the docs in the order that you want with something like
let $uris := ("/doc2", "/doc1", "/doc3")
let $docs := map:new(
fn:doc($uris) ! map:entry(xdmp:node-uri(.), .)
)
for $i in $uris
return map:get($docs, $i)
Related
I am creating a vertex with multiple edges but need a bit of help writing a query to retrieve the data.
Creation query
g.addV("referral")
.as("r")
.property("createdAt", Date.now())
.addE("prospect")
.from_("r")
.to(__.V(user.id))
.addE("opportunity")
.from_("r")
.to(__.V(second_user.id))
.addE("referredBy")
.from_("r")
.to(__.V(business.id))
.select("r")
.next()
I want to run a query that gets data from the first and second user. So far I have
g.V(business.id) //business
.in_("opportunity")
.as("referral")
.outV("referredBy")
.as("referrer")
.inV("prospect")
.as("prospect")
.select("referral", "referrer", "prospect")
.toList()
.next()
I'm getting an error when running this query. I basically want an array of a referral, referrer and prospect in one object that I can iterate through. Also any help on making my initial query better would be helpful.
Please let me know if this makes sense or if you need any other info. Any help would be appreciated.
The errors are because you are using outV when you should be using out. You only need to use inV and outV after outE and inE. So your query should be
g.V(business.id) //business
.in("opportunity")
.as("referral")
.out("referredBy")
.as("referrer")
.in("prospect")
.as("prospect")
.select("referral", "referrer", "prospect")
.toList()
Also you don't need next as you already have toList.
Lastly rather than use as and select I would look at the path step instead.
g.V(business.id) //business
.in("opportunity")
.out("referredBy")
.in("prospect")
.path()
.toList()
I would like to compare a datetime value (from a database) with the current time and check whether the current time is before or after the value in the database. This is done in a Symfony project. I tried to follow the instructions on the Symfony website.
So I wrote the following Doctrine query in a Repository Class which checks for a user lockout time and checks if it still lies in the future:
$user_id = 1; // Just giving $user_id a value for this example
$qb = $this->createQueryBuilder('user')
->andWhere('user.lockout_time > :time')
->setParameter('time', date("Y-m-d H:i:s"))
->andWhere('user.user_id = :user_id')
->setParameter('user_id', $user_id);
$query = $qb->getQuery();
echo $query->getSQL();
die;
When running this, both Where clauses contain "?" in the comparative value (e.g. WHERE user.lockout_time > ?). Obviously I want the actual values to be used in the query.
Initially I thought the date() function might be the issue, but even if I just use the :user_id I get the above error.
If I write ->andWhere('user.user_id = 1') I get the desired result.
If I replace :time with some date in the format 'Y-m-d H:i:s', I get the message "Error: Expected end of string..." (with the ... being the value for the Hour).
So both my setParameter() lines are not passing the values set in them. What am I overlooking?
Edit:
The suggested question here is not a duplicate. That just helps me see the query that is sent off. It was helpful in preparation of this question.
So here my own answer after some (= way too much) time of digging around.
The "?" are escaped values and do not represent what is actually in the query (which is another reason the above link doesn't help). To resolve this I resorted to monitoring the MySQL general log.
Here how to get to it, if someone has the same question. This log shows the actual SQL query.
I was wondering if there is a way for me use a result from search function in MarkLogic and use it in multiple transformation queries that I have.
For eg.
let $uris := cts:uris(("/example/"),(),cts:element-query(xs:QName("cd:documentTitle"),cts:element-value-query(xs:QName("cd:id"),"abc")))
return (fn:count($uris), $uris)[1 to 20]
The above query say returns me URI for 20 documents. How can I save this result or re-use this result for multiple transformations that I have. All of them working on the same result set but performing different tasks.
Any help would be greatly appreciated.
I'm going to guess you're using CORB to process data based on that return.
You could instead run your query in QConsole or similar and write the following in your URIs module:
let $uris = ("/1.xml", "/2.xml", ...)
return (fn:count($uris), $uris)
dayPath = ref.path.toString() + '/' + configId + '/screens/' + screenIndex + '/days/',
// the ref for the days object
daysRef = fbutil.ref(dayPath),
// the sync for the days object
daysSync = fbutil.syncObjectReference(daysRef);
// the collection as a $firebase array
var list = daysSync.$asArray(),
items = [],
number;
console.log(list);
list.$add({dummy: 'Test'});
According with the documentation, when I use $add with $asArray, the $add supposed to do a "push". But instead it's creating a hash key instead a numeric index.
So, the dummy: test has a parent containing a hash key. The expected is a numeric index, I mean : array item.
Can someone give me some help? I just have 1 week of experience in this database.
The result is this one...
screens
...0
.......days
..........0
..........1
..........2
.........-JrT5ZATDELIR3gXAvah
................dummy: test
AngulareFire is built on the Firebase JavaScript SDK. So when AngularFire's documentation says it uses push internally, it is not referring to JavaScript's Array.push, but to Firebase's push operation. And Firebase's push generates its own keys, it does not generate regular array indexes.
The reason for that is best explained in Firebase's documentation on arrays, but essentially boils down to: arrays don't work well in distributed environments, because all clients have to agree on the array.length in order to be able to add a new item.
So $firebaseArray.$add will generated a so-called push ID. They are ordered, like array indexes, but can be generated across clients without risk of conflicts.
I noticed that you're on a somewhat older version of AngularFire. I highly recommend that you follow the "official" quickstart and guide for AngularFire.
I would like to comment but i don't have enough reputation yet so i'm doing it here.
The solution in my eyes is very simple:
Instead of:
list.$add({dummy: 'Test'});
Do:
list[index] = {dummy: 'Test'};
I need to fetch from BaaS data store all records that doesn't match condition
I use query string like:
https://api.usergrid.com/<org>/<app>/<collection>?ql=location within 10 of 30.494697,50.463509 and Partnership eq 'Reject'
that works right (i don't url encode string after ql).
But any attempt to put "not" in this query cause "The query cannot be parsed".
Also i try to use <>, !=, NE, and some variation of "not"
How to configure query to fetch all records in the range but Partnership NOT Equal 'Reject' ?
Not operations are supported, but are not performant because it requires a full scan. When coupled with a geolocation call, it could be quite slow. We are working on improving this in the Usergrid core.
Having said that, in general, it is much better to inverse the call if possible. For example, instead of adding the property when the case is true, always write the property to every new entity (even when false), then edit the property when the case is true.
Instead of doing this:
POST
{
'name':'fred'
}
PUT
{
'name':'fred'
'had_cactus_cooler':true
}
Do this:
POST
{
'name':'fred'
'had_cactus_cooler':'no'
}
PUT
{
'name':'fred'
'had_cactus_cooler':'yes'
}
In general, try to put your data in the way you want to get it out. Since you know upfront that you want to query on whether this property exists, simply add it, but with a negative value. The update it when the condition becomes true.
You should be able to use this syntax:
https://api.usergrid.com/<org>/<app>/<collection>?ql=location within 10 of 30.494697,50.463509 and not Partnership eq 'Reject'
Notice that the not operator comes before the expression (as indicated in the docs).