I’m trying to use apigility with doctrine’s mongodb odm.
I’ve set up my documents and configured the doctrine module as should.
I’ve inserted (manually) one document to mongo, and defined a code-based rest service, with its “fetch” method (in the resource class) to return the document's repository "find" return value.
When I call the endpoint (without the ID) I get an array of the single document I’ve inserted, but it’s not shown correctly:
{
"_links": {
"self": {
"href": "http://localhost:8888/posts"
}
},
"_embedded": {
"posts": [
{
"\u0000MyApp\\Document\\Post\u0000id": "5389db47075000812e55bd7d",
"\u0000MyApp\\Document\\Post\u0000title": "My Post",
"\u0000MyApp\\Document\\Post\u0000description": "This is my post",
"_links": {
"self": {
"href": "http://localhost:8888/posts/1"
}
}
}
]
},
"total_items": 1
}
There are (at least) two problems with this output:
The key of each property is weirdly formatted. it contains the complete namespace with the document name, and the utf8 code for NULL
The “self” link does not use the correct id (it uses the number 1 instead of the mongodb autogenerated id).
What is wrong/missing ?
This happens when php uses ObjectProperty (\Zend\Stdlib\Hydrator\ObjectProperty )hydrator for populating the Objects.And in Apigility if you dont specify a hydrator then it will fall back to ObjectProperty hydrator(Default), which seems to be the case with your ouput.
Use Classmethods hydrator (\Zend\Stdlib\Hydrator\ClassMethods) instead.
Related
I follow spring boot mongodb tutorail on the official site to create employer class and table and it works fine.
Then, I created another class call account which I used exactly the same way to implement.
/api/account gives me Json file with empty data.
Enter : localhost:8000/api/
result:
{
"_links":{
"employer":{
"href": "url/api/employer"
"templated": true
}
"account":{
"href": "url/api/account"
"templated":true
profile:{
href: "url/api/profile"
}
I entered localhost/api/account
result:
{
"_embedded":{
"account" :[{}]
}
my mongo db - "account" collection has two document data and both "employer" and "account" collection are under test database.
I'm just getting started with mongoDB, and coming from a MySQL environment I'm having trouble figuring out how have my documents automatically have fields such as UPDATED, CREATED, DELETED
So when I create an entry like this:
{
"email": "some#test.com",
"name": "bob"
}
I would like it to automatically become this:
{
"email": "some#test.com",
"name": "bob",
"CREATED": 1567120458,
"UPDATED": 1567120458,
"DELETED": null
}
I have found https://docs.mongodb.com/manual/reference/operator/update/currentDate/ this resource which talks about a way of inserting dates, but I am not sure how to use this, or where to place this.
{ $currentDate: { <field1>: <typeSpecification1>, ... } }
I don't know what this piece of code means or where to use it.
I've installed Stuido 3T to help me manage the database, but I don't see any option to use this piece of code.
Construct your query use Date:
db.example.insert({"date":new Date(Date.now())})
Can anyone tell me why when I use DataExplorer for CosmoDb DB I get the following:
{
"id": "d502b51a-e70a-40f1-9285-3861880b8d90",
"Version": 1,
...
}
But when I use Robomongo I get:
{
"Version" : 1,
...
}
minus the id?
Thanks
I tried to repro your scenario but it all worked correctly.
The Mongo document in Portal Data Explorer:
The Mongo document in Robo 3T:
They both have the id property.
Are you applying Projections on Robomongo / Robo 3T?
At this moment cosmodb works separately SQL API and Mongo API, each one has different implementation, SQL API use JSON and Mongo use BSON, you need to be clear this while you are creating the document.
If you create the document with a BSON-based tool like Robo3t for example, you are going to get something like this:
{
"_id": {
"$oid": "5be0d98b9cdcce3c6ce0f6b8"
},
"name": "Name",
"id": "5be0d98b9cdcce3c6ce0f6b8",
...
}
Instead, if you create your document with JSON-based like Data Explorer, you are going to get this:
{
"name": "Name",
"id": "6c5c05b4-dfce-32a5-0779-e30821e6c510",
...
}
As you can see, BSON-based needs that _id and inside $oid be implemented to works right, while JSON-based only id is required. So, you need to add the properties while you save the document (see below) or open it with the right tool, as Matias Quaranta recommend, use Azure Storage Explorer or even Data Explorer to get both protocols properly.
Also, if you use a system to create the document and you want to use BSON format, You need to add the $oid, for example in core net is something like this:
public bool TryGetMemberSerializationInfo(string memberName, out BsonSerializationInfo serializationInfo)
{
switch (memberName)
{
case "Id":
serializationInfo = new BsonSerializationInfo("_id", new ObjectIdSerializer(), typeof(ObjectId));
return true;
case "Name":
serializationInfo = new BsonSerializationInfo("name", new StringSerializer(), typeof(string));
return true;
default:
serializationInfo = null;
return false;
}
}
I am new to Cloudant and I need to do a simple query on a specific document field. My documents have the following structure and I need to get only the documents with status=SIGNED
{
"_id": "3ddb4058f3b24a7a9c585f997e30ff78",
"_rev": "3-757c82c48f4e7c333911be6859aff74e",
"fileName": "Generali Architects",
"status": "SIGNED",
"user": "italy",
"_attachments": {
"Generali Architects": {
"content_type": "application/pdf",
"revpos": 3,
"digest": "md5-9hqSif7CzQ2yvKxSSbj+dw==",
"length": 323653,
"stub": true
}
}
}
Reading Cloudant documentation I created the following Design Document with a related view which returns exactly what I expected
Then from my Java application I use the following code
String cloudantView = "_design/signedDocs/status-signed-iew";
List<SignDocDocument> docs =
db.view(cloudantView).includeDocs(true).query(SignDocDocument.class);
which always returns me "org.lightcouch.NoDocumentException: Object Not Found"
Any idea which kind of mistake I am making here?
Thank you very much
Is it the typo in "_design/signedDocs/status-signed-iew"; e.g. that should be "_design/signedDocs/status-signed-view"; (depending on how your java library works...).
Always worth checking the view by direct access in your browser, too, just to make sure it's returning the expected data.
As I create entities in an Orion server, I can search by ID, as flat or using regular expressions:
http://<localhost>:1026/v1/queryContext
Content:
{
"entities": [
{
"type": "Sensor",
"isPattern": "true",
"id": "sensor_1.*"
}
],
"attributes": ["temperature","humidity"]
}
In the above example I'd get all objects of type "Sensor" whose ID starts with "sensor_1", and their attributes "temperature" and "humidity". I wonder if there is any way that would allow me to search by specific attribute value, for example to get those sensors whose humidity is over "60.2", or this selection must be done over the retrieved data queried by ID.
Not in the current Orion version (0.19.0) but it will be possible in the future. Have a look to the attribute::<name> filter with the = operator in this document.