Using existing collection with grapher


#1

Hi guys.
I have a collection of documents like this

{
	"_id" : "dGXNjsak3L9fv3RB2",
	"name" : "myProject",
	"domainUrl" : "https://mySite.com",
	"createdAt" : ISODate("2017-11-08T13:49:14.392Z"),
	"ownerId" : "TyNFXKjARbhQ3NbEm",
	"users" : [
		{
			"userId" : "TyNFXKjARbhQ3NbEm",
			"email" : "email@gmail.com",
			"createdAt" : ISODate("2017-11-08T13:49:14.394Z"),
			"isAdmin" : true
		},
		{
			"userId" : "pDSB9euAsWEzcEQht",
			"email" : "anotherEmail@gmail.com",
			"createdAt" : ISODate("2017-11-15T13:18:00.275Z"),
			"isAdmin" : false
		}
	]
}

What would be the best way to add links for this collection?


#2

Unfortunately you will have to rename “userId” in “users” to “_id”. Then you can do like this:

collection.addLinks({
  owner:{
    type:'single',
    collection:Meteor.users,
    field:'ownerId'
  },
  linkedUsers:{
    type:'many',
    collection:Meteor.users,
    field:'users',
    metadata:{}
  }
})

#3

Thanks.
Do you know any place I can find some better documentation?
The official one seems to be very shallow.


#4

@hayk Grapher is going to be worked on and have 1.3 launched before end of 2017.

Regarding your question, try refactoring userId to _id. You could write a simple migration script with $rename modifier . Custom field names for meta links are not currently supported. The rest is what @herteby said.

Please read the guide completely! Most people dive directly into the API and they have no clue what’s going on , + I totally agree, the docs need some love, and they will receive it.

http://grapher.cultofcoders.com/guide/links.html it’s explained how a Many Meta link looks like. Please submit issues to https://github.com/cult-of-coders/grapher-docs where you need more clarification. We are going to make it much much better.

Thanks


#5

@diaconutheodor thanks for the suggestion.
I really like the idea of the grapher but for now it seems hard for me to grasp it on a more practical level.
So I think having detailed docs and guides will be very helpful. I’ll make sure to submit issues, at least I can I help you that way. Thanks.