Maybe I'm completely wrong, but since projects that I start today, when I use meteor mongo to connect directly to the mongodb, and insert a record (with mycol.insert(..) the _id field is surrounded with ObjectId("12345555...").
When adding a record from code this is not the case.
So, records added via Meteor Mongo are not recognised inside the app any longer.
I have done this in the past so often...
what's happening here?
That's the MONGO way and you see this because you are using the Mongo shell. Meteor defaults to a different method (cf below) which you see when you use it programmatically. Check Meteor docs on new Mongo.Collection
idGeneration String
The method of generating the _id fields of new documents in this collection. Possible values:
'STRING': random strings
'MONGO': random Mongo.ObjectID values
The default id generation technique is 'STRING'
In Meteor, if you write
Steffo = new Meteor.Collection("steffo", {idGeneration: 'STRING'});
this will result in entries
{ "foo" : "bar", "_id" : "68FWFNGRAuRt82pWy" }
If you use
Paul = new Meteor.Collection("paul", {idGeneration: 'MONGO'});
you'll get
{ "foo" : "bar", "_id" : ObjectId("26cfdb5f200adfa0b55a50d3" }
The latter happens when you use Mongo shell.
Related
According to the docu "[...] VueFire will automatically bind up to one nested references.". That works well, if I retrieve an object (map) from the database with a property being a ref: The ref gets ressolved automatically on the client (ref_property will not hold the path to the object (e.g. users/123) but the actual data ({username: 'john', hometown: 'autumn'}).
Question is: How do I update a ref_property (e.g. suppose a last_edit_by_ref) on the client in a way, that a.) VueFire is able to resolve this to a valid JSON for the UI and b.) make sure that it's stored as a ref in the database at the same time?
I tried to fetch the referenced object (again) from the collection as explained here ("To write a reference to a document, you pass the actual reference object"). The issue with this is however, that VueFire does not ressolve this, leading to empty values in the UI:
post.last_edit_by_ref = db.collection('users').doc('123')
Background: If I'm setting plain JSON, the property is no longer stored as a reference in the database. This is bad, since the linked object is likely to be changed (and the linking objekt would then hold copied, outdated data).
It does not related to VueFire. It is how firebase parse the Object it get in the set/update methods.
If you focus on this part:
const data = {
age: 18,
name: "John",
carRef: db.collection('cars').doc('john-car'),
}
await db.collection('users').doc('john').set(data);
You will have the ref in firestore. And in turn, VueFire will automatic bind the object.
For your case, i think you will need to find a way to get the db.collection('users').doc(last_edit_user_id) to make the ref for post.
I am currently trying to fetch data from FireStore using EmberFire. Right now, my collection is /users and in there I store a user ID. Under the user ID I create another subcollecion, containing an array called /presets.
I want to use EmberFire to retrieve the presets for the currently logged in user. How can I tell this to EmberFire?
I tried fetching other data using EmberFire and it worked fine. For example, fetching documents from a collection works perfectly fine, I just have never used sub collections. Hence the question.
What I would like to achieve is something like
this.store.query('/users/pLvAT0TSbAjsnXoVmMF7yEG3mkW2/presets')
to get to the data stored in (collection users) -> (document pLvAT0TSbAjsnXoVmMF7yEG3mkW2) -> (collection presets).
Of course I would like to then use the traditional workflow to turn the documents in presets into views.
Right now, I am only able to work with a single collection. Nested collections are not something I am able to work with.
Does anyone have an idea on how to solve this?
A general answer would be:
this.store.find('users', 'pLvAT0TSbAjsnXoVmMF7yEG3mkW2').then((user)=>{
return user.get('presets');
})
But it assumes some things done "the Ember way":
There's User model
There's a Preset model
There's a hasMany relationship between User and Preset like this:
// app/models/user.js
import DS from 'ember-data';
const { Model, attr, hasMany } = DS;
export default Model.extend({
presets: hasMany('preset', { subcollection: true })
});
Although the current version of Emberfire (v3-rc2) doesn't work pretty well with Subcollections, you'll be able to fetch records, but not create or update one.
Sources:
Emberfire guides (right now kind of empty, but hopefully someday it'll have good info)
I want to do the following using Asp.net Web API 2 and RavenDB.
Send a string to RavenDB.
Lookup a document containing a field called UniqueString that contain the string i passed to RavenDB.
Return either the document that matched, or a "YES/NO a document with that string exists" - message.
I am completely new to NoSQL and RavenDB, so this has proven to be quite difficult :-) I hope someone can assist me, and i assume it is actually quite easy to do though i haven't been able to find any guides showing it.
This has nothing to do with WebAPI 2, but you can do what you ask for using RavenDb combined with WebAPI 2.
First you need to have an index (or let RavenDb auto create one for you) on the document and property/properties you want to be indexed. This index can be created from code like this:
public class MyDocument_ByUniqueString : AbstractIndexCreationTask<MyDocument>
{
public override string IndexName
{
get { return "MyDocumentIndex/ByUniqueString"; }
}
public MyDocument_ByUniqueString()
{
Map = documents => from doc in documents
select new
{
doc.UniqueString
};
}
}
or created in the RavenDb Studio:
from doc in docs.MyDocuments
select new {
doc.UniqueString
}
After that you can do an "advanced document query" (from a WebAPI 2 controller or similar in your case) on that index and pass in a Lucene wildcard:
using (var session = documentStore.OpenSession())
{
var result = session.Advanced
.DocumentQuery<MyDocument>("MyDocumentIndex/ByUniqueString")
.Where("UniqueString: *uniq*")
.ToList();
}
This query will return all documents that has a property "UniqueString" that contains the term "uniq". The document in my case looked like this:
{
"UniqueString": "This is my unique string"
}
Please note however that these kind of wildcards in Lucene might not be super performant as they might need to scan large amount of texts. In the RavenDB documentation there's even a warning aginst this:
Warning
RavenDB allows to search by using such queries but you have to be
aware that leading wildcards drastically slow down searches. Consider
if you really need to find substrings, most cases looking for words is
enough. There are also other alternatives for searching without
expensive wildcard matches, e.g. indexing a reversed version of text
field or creating a custom analyzer.
http://ravendb.net/docs/article-page/2.0/csharp/client-api/querying/static-indexes/searching
Hope this helps!
Get the WebApi endpoint working to collect your input. This is independent of RavenDB.
Using the RavenDB client, query the database using Linq or one of the other methods.
After the document is retrieved you may need to write some logic to return the expected result.
I skipped the step where the database gets populated with the data to query. I would leverage the RavenDB client tools as much as possible in your app vs trying to use the HTTP api.
I do something like this:
var temp = $scope.names.$add({"firstname" : $scope.firstname, "lastname" : $scope.lastname, "school" : $scope.selectedSchool});
I get a returned object, but when I try
$log.log(temp.toString());
I get just the object, whereas the documentation for firebase says I should see the path to the string of my new firebase URL. I also tried
$log.log(temp.name());
And same result, is this related to the implementation of those "functions" in angularfire, or to actual firebase itself?
I'm trying to syncronize adding "names" to a names portion of my json object, and then following it up with creating a section in my json object where I can get more details of the individual and so I want to match up the key's
kinda like this JSON Data structure resulting in the least passed data from database
I don't see how to get the above to work, and I saw (at one point, can't find the link now), that firebase was recommending using transaction not the "once" operation, so I was hoping I would get the individuals key, then pass that into creating a new firebase "subobject?" that matched it.
I am getting below error whilst trying to persist an object that has a collection of interfaces which I want to hold a couple of different types of objects. Seems to be happening almost randomly. Sometimes after restarting it works ok ( I might be doing something wrong though).
class CommentList {
#Persistent
#Join
ArrayList<IComment> = new ArrayList<IComment>();
}
somewhere else...
CommentList cl = new CommentList();
cl.addComment( new SimpleComment() );
cl.addComment( new SpecialComment() );
repo.persist( cl );
I can see the join table has been created in my DB along with ID fields for each of the Implementation classes of IComment.
SimpleComment and SpecialComment implement IComment. If I just add a SimpleComment it works fine. As soon as I start trying to add other types of objects I start to get the errors.
error im getting
java.lang.ClassCastException: Field "com.myapp.model.CommentList.comments" is a reference field (interface/Object) of type com.myapp.behaviours.IComment but DataNucleus is unable to assign an object of type "com.myapp.model.ShortComment" to this field. You can only assign this field to a type specified by the "implementation-classes" extension attribute.
at org.datanucleus.store.mapped.mapping.MultiMapping.setObject(MultiMapping.java:220)
at org.datanucleus.store.mapped.mapping.ReferenceMapping.setObject(ReferenceMapping.java:526)
at org.datanucleus.store.mapped.mapping.MultiMapping.setObject(MultiMapping.java:200)
at org.datanucleus.store.rdbms.scostore.BackingStoreHelper.populateElementInStatement(BackingStoreHelpe
r.java:135)
at org.datanucleus.store.rdbms.scostore.RDBMSJoinListStoreSpecialization.internalAdd(RDBMSJoinListStore
Specialization.java:443)
at org.datanucleus.store.mapped.scostore.JoinListStore.internalAdd(JoinListStore.java:233)
When it does save, if I restart the server and try to query for a list of the comments, I get null values returned.
I'm using mysql backend - if I switch to db4o it works fine.
Please let me know if any info would be useful.
If you have any idea where I might be going wrong or can provide some sample code for persisting collection of different objects implementing the same interface that would be appreciated.
Thanks for any help.
Tom
When I used interfaces I just enabled dynamicSchemaUpdates (some persistence property with a name like that) and FK's are added when needed. The log gives all SQL I think
I fixed this by specifying
<extension implemention-classes="SimpleComment SpecialComment"/>
for the field cl in my pacakge.jdo.