Document erased automatically by system immediately after insert


#1

Hi guys, I have tried asking about this several times here and no reply yet so trying again.

I have created a mongo collection and am trying to insert data to the collection but everytime I insert a document it is immediately deleted a few miliseconds after insertion. There are no errors. I can watch it insert and then be removed in mongol. If I do it directly into the mongo shell it is saving no problem so it seems something from meteor is doing this.

Please help as this is preventing me finishing my app and is really making me pull my hair out for over a week now no idea whats doing it. I have tried everything I can think, refactored all my code incase of a reserved word or something else messing it up. I cannot figure out why this collection will not let me insert.

Important to note this collection unlike all my others requires me to set different allow rules to insert.

Allow file

Posts.allow
	insert: (userId, doc) ->
		userId == doc.owner
	update: (userId, doc, fields, modifier) ->
		userId == doc.owner
	remove: (userId, doc) ->
		userId == doc.owner

PurchaseOrders.allow
	insert: (userId, doc) ->
		true
	update: (userId, doc, fields, modifier) ->
		true
	remove: (userId, doc) ->
		true

The collection I am trying to insert too is PurchaseOrders and I must set it to this true statement only as if I try to set it as the posts collection I get a permission denied. Very strange as I can insert to Posts no problem. I have reset the database uncountable times and the same issue persists.

Collection

@PurchaseOrders = new Meteor.Collection('purchaseorders');

Schemas.PurchaseOrders = new SimpleSchema
  message:
    type: String
    label: "Extra message or instructions"
    optional: true
    autoform:
      afFieldInput:
        type: "textarea"
        rows: 4

	purchaseStatus:
		type: String
    optional: true

	ordersList:
		type: String
    optional: true

	createdAt:
		type: Date
		autoValue: ->
			if this.isInsert
				new Date()

	updatedAt:
		type:Date
		optional:true
		autoValue: ->
			if this.isUpdate
				new Date()

	owner:
		type: String
		regEx: SimpleSchema.RegEx.Id
		autoValue: ->
			if this.isInsert
				Meteor.userId()
		autoform:
			options: ->
				_.map Meteor.users.find().fetch(), (user)->
					label: user.emails[0].address
					value: user._id

PurchaseOrders.attachSchema(Schemas.PurchaseOrders)

PurchaseOrders.helpers
	ownersName: ->
		user = Meteor.users.findOne(@owner)
		if user?.profile?.firstName? and user?.profile?.lastName
			user.profile.firstName + ' ' + user.profile.lastName
		else
			user?.emails?[0].address

  isOwner: ->
    return this.owner == Meteor.userId()

	#title: ->
		#product = Products.findOne(@productId)
		#return product.title

I cannot insert to this schema no matter what i try. Please help


#2

Additional: Also if I insert directly with mongol I get the alert ‘Document successfully inserted’ but no document is created.


#3

Update Now fixed. I deleted everything to do with this collection and started from scratch after resetting the database. The same code is now working fine.

This really is one friggin strange bug I hope I dont run into it again. Or anyone else does. It’s still not solved as to why this happens…