Reputation: 300
Can someone explain why am i getting the full value of ObjectID instead just the clean ID?
This is what i'm getting:
And the HTML output:
<a href="/summary/ObjectID(%2254ab87a24c38814aa128da7b%22)">My Post</a>
I haven't done anything out of the ordinary. Very basic stuff right now. Just trying out Meteor for the first time.
Routing: lib/router.js
// Dashboard
Router.route('/dashboard', {name: 'dashboard'});
// Post detail
Router.route('/summary/:_id', {
name: 'postSummary',
data: function() {
return Post.findOne(this.params._id);
}
});
List page template: templates/posts/post_dashboard.html
{{#each posts}}
<tr>
<td>
<p><a href="{{pathFor 'postSummary'}}">{{title}}</a></p>
<p><small>Created at {{createdAt}}</small></p>
</td>
...
</tr>
{{/each}}
Detail page template: templates/posts/post_summary.html
<template name="postSummary">
{{> postHeader}}
<h3>{{title}}</h3>
</template>
Template helper: templates/posts/posts.js
Template.dashboard.helpers({
posts: function () {
return Post.find({});
}
});
And here's the packages i have installed, just in case it's necessary.
meteor-platform
autopublish
insecure
matthew:foundation5-sass
iron:router
jquery
useraccounts:core
useraccounts:foundation
accounts-password
accounts-facebook
accounts-google
accounts-ui-unstyled
aldeed:autoform
aldeed:collection2
forwarder:autoform-wizard
fortawesome:fontawesome
Upvotes: 1
Views: 996
Reputation: 573
Mongo ObjectID has a property: _str
It includes string representation of the ID.
Upvotes: 0
Reputation: 8013
When you query the Posts
collection from the console, is the _id
in the returned document(s) a string literal or an ObjectId Object?
Assuming it's the latter, that's why this is happening, and if so, it's probably going to be because you've populated the collection by using insert
in the Mongo shell (or alternatively restored from an existing MongoDB). By default, Meteor insert uses strings for the auto-added id when the id is not specified, whereas Mongo uses ObjectIds.
Hope that helps, but let me know if I'm on totally the wrong track!
Upvotes: 5