Why do I need to import collections in router file? - mongodb

I'm building simple webs with meteor, just to get to know each other, and I'm playing with iron:router as router.
The "problem" I got is that in my meteorapp/lib/routes.js I need to import my collection file which is in meteorapp/imports/ui/reservations.js:
import { Reservations } from '../imports/api/reservations.js';
Otherwise I'm not able to reach it in the template, even though I imported it same line (different path) in the templage.js file like this:
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
//collection Reservations
import { Reservations } from '../api/reservations.js';
import './roomSchedule.html';
Template.roomSchedule.onCreated(function roomScheduleOnCreated() {
Meteor.subscribe('reservations');
});
Template.roomSchedule.helpers({
allHours() {
return Reservations.find();
},
});
I don't know if this would help, meteor list output:
user#laptop:~/Documents/meteorApps/mymeteorApp$ meteor list
blaze-html-templates 1.1.2 Compile HTML templates into reactive UI with Meteor Blaze
ecmascript 0.10.3* Compiler plugin that supports ES2015+ in all .js files
es5-shim 4.7.3 Shims and polyfills to improve ECMAScript 5 support
insecure 1.0.7 (For prototyping only) Allow all database writes from the client
iron:router 1.1.2 Routing specifically designed for Meteor
meteor-base 1.3.0 Packages that every Meteor app needs
mobile-experience 1.0.5 Packages for a great mobile user experience
mongo 1.4.3 Adaptor for using MongoDB and Minimongo over DDP
reactive-var 1.0.11 Reactive variable
shell-server 0.3.1 Server-side component of the `meteor shell` command.
standard-minifier-css 1.4.1 Standard css minifier used with Meteor apps by default.
standard-minifier-js 2.3.2 Standard javascript minifiers used with Meteor apps by default.
tracker 1.1.3 Dependency tracker to allow reactive callbacks
So it works... but don't know why... Thanks in advance to everyone.
Axel.

Related

Upgrading mongo-java-driver to Version 3.9.1

I am in the midst of upgrading the Spring version of one of our projects. As a result of this, the MongoDB library also had to be upgraded.
I am not able to track what the previous version of the MongoDB library used was, but the current version is now 3.9.1.
I have the following piece of code that doesn't work because of the upgrade, how should I rewrite it?
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.ServerAddress;
public sampleMethod() {
MongoClient client = null;
if (...) {
List<ServerAddress> saList = new ArrayList<>();
for (...) {
saList.add(...);
}
client = new MongoClient(saList);
} else if (...) {
MongoClientURI mongoClientURI = new MongoClientURI("mongodb://...");
client = new MongoClient(mongoClientURI);
} else {
MongoClientURI mongoClientURI = new MongoClientURI("mongodb://..." + this.encryptedProperties.getProperty("mongo.username") + "....");
client = new MongoClient(mongoClientURI);
}
return new MongoTemplate(client, srcDbname);
}
The problem now is with the return statement, because post Version 2.1, MongoTemplate's signature is now public MongoTemplate(com.mongodb.client.MongoClient mongoClient, String databaseName). Pre Version 2.1, it was public MongoTemplate(com.mongodb.MongoClient mongoClient, String databaseName).
I was looking at the documentation for the MongoClient interface (com.mongodb.client.MongoClient package) & it states that "Instances of this class can be created via the MongoClients factory.". Looking at MongoClients, the methods can't accommodate the creation of MongoClient with parameters List<ServerAddress>, MongoClientURI like MongoClient (com.mongodb.MongoClient package) does.
Package
Old Version
Link
New Version
Link
mongo-java-driver / com.mongodb
not sure, couldn't locate but will update
-
3.9.1
https://www.javadoc.io/static/org.mongodb/mongo-java-driver/3.9.1/index.html
org.springframework.data:spring-data-mongodb
2.0.8.RELEASE
https://docs.spring.io/spring-data/mongodb/docs/2.0.8.RELEASE/api/
3.2.0
https://docs.spring.io/spring-data/mongodb/docs/3.2.0/api/
Please bear with me as I am a junior dev (6 months of work experience) & I'm not familiar with upgrading project versions, thank you for your understanding
I am not sure how to proceed, I am currently reading the docs & doing some Google searches to see what a possible solution would be
I don't have experience in MongoDB
It looks like you're upgrading to version 3.2 of Spring Data MongoDB. As per the reference documentation, that major version series (3.x) requires you to use the 4.x version of the MongoDB Java Driver.
7.1. Dependency Changes Instead of the single artifact uber-jar mongo-java-driver, imports are now split to include separate
artifacts:
org.mongodb:mongodb-driver-core (required)
org.mongodb:mongodb-driver-sync (optional)
org.mongodb:mongodb-driver-reactivestreams (optional)
Depending on the application one of the mongodb-driver-sync,
mongodb-driver-reactivestreams artifacts is is required next to the
mandatory mongodb-driver-core. It is possible to combine the sync and
reactive drivers in one application if needed.

What is the import statement for cordova-plugin-sqlite-2 in Ionic framework?

I am trying to use cordova-plugin-sqlite-2 plugin in my Ionic app, but I'm not sure how to use its features for opening or creating a database .
What import () statement should I give to use this plugin ?
I have referred this Question in which 'import { SQLite } from 'ionic-native';
is used , but it is showing error when used.
I'm not sure if you're trying to use sqlite only or some other DB, but I have recently used PouchDB inside my Ionic5+ReactJs+Typescript app, and here is what I did:
Install the necessary packages
npm install pouchdb pouchdb-adapter-cordova-sqlite cordova-plugin-sqlite-2
#types/pouchdb #ionic-native/sqlite
Please note that #types packages are for typescript support.
Create a sample database
import PouchDB from "pouchdb";
import "cordova-plugin-sqlite-2/dist/sqlite-plugin";
import cordovaSqlitePlugin from "pouchdb-adapter-cordova-sqlite";
PouchDB.plugin(cordovaSqlitePlugin);
let sampleDB = new PouchDB("sampleDatabase", {
adapter: "cordova-sqlite",
});
After that you can use the database object directly
sampleDB.post({name: "my first object"});

Axon - The type DefaultMongoTemplate is deprecated

I am developing Spring Boot + AXON example from the link: https://blog.novatec-gmbh.de/event-sourcing-spring-boot-axon/ and just updated Spring Boot version 2.1.0.RELEASE.
Multiple markers at this line
- The type DefaultMongoTemplate is deprecated
- The constructor DefaultMongoTemplate(MongoClient) is
deprecated
Code
import com.mongodb.MongoClient;
import org.axonframework.eventsourcing.eventstore.EventStorageEngine;
import org.axonframework.mongo.eventsourcing.eventstore.DefaultMongoTemplate;
import org.axonframework.mongo.eventsourcing.eventstore.MongoEventStorageEngine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
#Configuration
public class AggregateConfig {
#Bean
public EventStorageEngine eventStore(MongoClient client) {
return new MongoEventStorageEngine(new DefaultMongoTemplate(client));
}
}
Looks like DefaultMongoTemplate code is deprecated, what's the replacement for it ?
As off Axon release 4.0, extension package, like Mongo, have been moved to a dedicated repository (which you can find here). Additionally, when upgraded from Axon 3.x to 4.0, we have replaced several constructors on the infrastructure components in favor of the Builder pattern.
One of these which has undergone that change, is the DefaultMongoTemplate.
A part from that story though, I just checked out Axon 3.x (as I assume you're not looking at 4.0 at the moment), and the org.axonframework.mongo.eventhandling.saga.repository.DefaultMongoTemplate is deprecated in favor of the org.axonframework.mongo.DefaultMongoTemplate. I pull this from the javadoc at the moment, so I had hoped that would be visible on your side.
Any how, I hope this helps you out!
And if you've got the change, I'd recommend to upgrade to Axon 4.x, as new features will get added in that version instead of version 3.x.

SyntaxError: export declarations may only appear at top level of a module when trying to import office-ui-fabric in a Gatsbyjs blog

I'm trying to add OfficeUI fabric components in a blog build using gatsby js.
As soon as I'm importing any component, the site stop to works.
Using develop command, I can see in the browser console : SyntaxError: export declarations may only appear at top level of a module
How to fix this ? (I'm very new to node dev).
Searches I've done suggest problems with babel not using the es2015 preset. However, I double checked, the .babelrc file is mentioning this preset.
Here's the complete operations I've done (on Windows 10 x64 if it matters):
cloned the gatsby-starter-blog-no-styles repo :
gatsby.cmd new someblog https://github.com/noahg/gatsby-starter-blog-no-styles
cd someblog
npm install
drink a coffee (will move to yarn soon)
Check that works
gatsby develop
Opened the browser (http://localhost:8000). Its Ok
added office ui fabric react components
npm install --save office-ui-fabric-react
Restart gatsby develop. Still working
change src/layouts/index.js file to import an office component
import React from 'react'
import Link from 'gatsby-link'
import { Button } from 'office-ui-fabric-react/lib/Button'
class Template extends React.Component {
....
And voilĂ ! it stop to works. In the browser console, I see an error : SyntaxError: export declarations may only appear at top level of a module
I put in GH a complete reproduction repository : https://github.com/stevebeauge/repro-gatsbyjs-officeui-error
[Edit] Digging a bit I can see in the generated 'common.js' file the error :
/***/ "./node_modules/office-ui-fabric-react/lib/Button.js":
/***/ (function(module, exports) {
export * from './components/Button/index';
//# sourceMappingURL=Button.js.map
/***/ }),
The export here seems to be forbidden, which leads to Babel issue (not found how to solve though)
Recently i stumbled upon the similar error, my solution was to explicitly import from lib-commonjs:
import { Button } from 'office-ui-fabric-react/lib-commonjs/Button';
instead of
import { Button } from 'office-ui-fabric-react/lib/Button'
Seems to be the error occurs since babel isn't converting office-ui-fabric-react to CommonJS module.

How to import new library in Angular2?

I want to use RxJS-DOM library to parse json data from file. I have some difficulties with including this library to Angular2 application. First, i installed RxJS-DOM with NPM. And i need to import this library to my service file with import expression.
import {name} from 'path/to'
How can i know which name and which path to use to import this library by analogy with, for example, import {Injectable} from 'angular2/core' ?
Do i need to include this library in index.html like this and why ?
Thank you.
Usually it's SystemJS, which is loading up modules for you. You're configuring it with a systemjs.config.js file or inline in your index.html. There you tell it to load packages from your node_modules folder and with which name you want to register it and so on.
If you're using the Angular 2 Quickstart project, and the Beta version of Angular 2, then the configuration is probably done in your index.html and rather minimal at that. You will find, that every extra NodeJS module you want to use, you have to import with a <script> tag. (That's not the case if you go the SystemJS config route)
So your base path it usually the node_modules folder, when you're importing in your TypeScript file. If you want to import "local" files that are not modules from your node_modules folder, you do that with
import {class} from './path/file';
Regarding your JSON problem - I would leverage Angular's Http class to read in JSON files like this:
interface IConfig {
thingEnabled: boolean;
otherStuff: string;
}
[...]
this.http.get('./config.json')
.map((res: Response) => res.json())
.subscribe((res: IConfig) => {
// do something with the already deserialized JSON here
console.log(res.otherStuff);
});