mongodb example

107 views
Skip to first unread message

Steve Schreiner

unread,
Jun 29, 2014, 9:27:16 PM6/29/14
to extdire...@googlegroups.com
I know this off topic, but can you add a grid example that deals with crud operations using a mongodb instead of the SimpleUserDb?

ralph

unread,
Jun 30, 2014, 11:50:05 AM6/30/14
to extdire...@googlegroups.com
Hi. 

I wrote a simple example with one grid.

Ralph

Steve Schreiner

unread,
Jul 1, 2014, 9:07:20 AM7/1/14
to extdire...@googlegroups.com
Wow! Thanks Ralph for going the extra mile and putting the example up there :)

I downloaded your project and imported into Intellij and see the errors in the attached screenshot.  Also please see the server log I get when trying to start up the project.

Thanks,
Steve
initialdataload error.png
serverlog.txt
Message has been deleted

Steve Schreiner

unread,
Jul 1, 2014, 9:41:52 AM7/1/14
to extdire...@googlegroups.com
As a side note, I noticed that the extjs app folder does not sit under the webapp folder like your other examples, but rather sits in its own static folder?

I commented out these lines in InitialDataLoad to get past the errors I indicated in the previous post, and the server starts up but when I go to the web page I get a generic error shown below

private void init(ClassPathResource randomDataResource) throws IOException {
if (userRepository.count() == 0) {
// try (BufferedReader reader = new BufferedReader(new InputStreamReader(
// new InflaterInputStream(randomDataResource.getInputStream(),
// new Inflater(true)), StandardCharsets.UTF_8))) {
// reader.lines().map(line -> line.split(Pattern.quote("|")))
// .map(s -> new User(s[0], s[1], s[2], s[3]))
// .forEach(user -> userRepository.save(user));
// }
}

}

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Jul 01 09:37:54 EDT 2014
There was an unexpected error (type=Not Found, status=404).
No message available

Ralph Schaer

unread,
Jul 1, 2014, 11:16:24 AM7/1/14
to extdire...@googlegroups.com
Hi 

One problem I see in the serverlog.txt is that the application cannot connect to mongodb. The example application tries to connect to localhost:27017. If mongodb is running on a different port or server you have to configure that in the src/main/resources/application.yml  file.

spring:

Ralph Schaer

unread,
Jul 1, 2014, 11:16:32 AM7/1/14
to extdire...@googlegroups.com
That is a feature of spring-boot

Here the link to the corresponding article in the spring boot documentation:

Ralph Schaer

unread,
Jul 1, 2014, 11:31:19 AM7/1/14
to extdire...@googlegroups.com
I tested it with IntelliJ IDEA 13.1.3 and it does work in my environment.
Here the steps I had to do to make it work:

1. Import project from GitHub with the "Checkout from Version Control" function. 

2. ctrl+shift+alt+s  Make sure the language level is "8.0". 
   Change the compiler output to ...eds-starter-mongodb\target\classes
   Not sure why IntelliJ uses eds-starter-mongodb\classes. That looks wrong to me.

3. Open pom.xml and remove the line <scope>provided</scope> from the spring-boot-starter-tomcat dependency
    <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
  </dependency>
    This is only necessary when you start the application with the main class Application. 
    You have to re-add the scope provided when you package the application (create the war).

4. Open console/terminal and cd into the static directory. Download ext folder with: sencha app upgrade -ext

5. Build js app with: sencha app build

6. Start mongodb

7. Start the application with Run 'Application.main()'

8. Open a browser and enter url: http://localhost


sam y

unread,
Jul 1, 2014, 11:57:01 AM7/1/14
to extdire...@googlegroups.com
Thanks Ralph for putting this example.

I was also trying to run this but wasnt really successful. I get the same error from my IntelliJ or from command line when I run the sencha command in the terminal at static folder as you mentioned below. I am new to Sencha and Sencha Cmd but any help is greatly appreciated. Btwn, thank you for all your work on ext direct, its a great framework.

sencha app upgrade -ext
Sencha Cmd v5.0.0.160
[ERR] Cannot satisfy requirements for "ext"!
[INF]    The following versions are available:
[INF]       5.0.0.732 ( ... compatible back to 4.0)
[INF]       5.0.0.736 ( ... compatible back to 4.0)
[INF]       5.0.0.970 ( ... compatible back to 4.0)
[INF]    The following versions can be satisfied:
[ERR]    The following versions cannot be satisfied:
[ERR]       framework package dependency: e...@5.0.1.1066 (No matches!)
[ERR] Cannot resolve package requirements
     at com.sencha.tools.pkg.PackageResolver.getPackages(PackageResolver.java:161)
     at com.sencha.command.environment.FrameworkEnvironment.loadFrameworkPackage(FrameworkEnvironment.java:183)
     at com.sencha.command.environment.AppOrPackageEnvironment.loadFrameworkConfig(AppOrPackageEnvironment.java:50)
     at com.sencha.command.environment.AppEnvironment.<init>(AppEnvironment.java:50)
     at com.sencha.command.environment.BuildEnvironment.load(BuildEnvironment.java:94)
     at com.sencha.command.environment.BuildEnvironment.load(BuildEnvironment.java:118)
     at com.sencha.command.environment.BuildEnvironment.load(BuildEnvironment.java:64)
     at com.sencha.command.Sencha.loadBuildEnvironment(Sencha.java:397)
     at com.sencha.command.Sencha.main(Sencha.java:126)

Ralph Schaer

unread,
Jul 1, 2014, 12:00:41 PM7/1/14
to extdire...@googlegroups.com
You have to change the extjs version to 5.0.0.970 in static/.sencha/app/sencha.cfg
Or you can checkout the application again from github. I already commited the change.



sam y

unread,
Jul 1, 2014, 12:05:45 PM7/1/14
to extdire...@googlegroups.com
Thanks for your super fast response. I just pulled the latest code and it seems to be building now. Its taking some time to download and its going on as I type this ...I will let you know how it goes ..thanks again !


--
You received this message because you are subscribed to a topic in the Google Groups "extdirectspring" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/extdirectspring/dER168Z4Yu4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to extdirectspri...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sam

unread,
Jul 1, 2014, 12:32:39 PM7/1/14
to extdire...@googlegroups.com
Thanks. Its working now. I am able to deploy it on tomcat and could run the functionality on user grid. All the users are also stored into mongodb. Thank you very much for your help.

Steve Schreiner

unread,
Jul 1, 2014, 3:16:41 PM7/1/14
to extdire...@googlegroups.com
Thanks Ralph.  I was able to successfully connect by defining the uri property which contained my remote mongo login info :)

spring:
  data:
    mongodb:
      uri: mongodb://localhost/test

Steve Schreiner

unread,
Jul 1, 2014, 3:19:53 PM7/1/14
to extdire...@googlegroups.com
Thanks again Ralph!  I followed these steps and then created a local tomcat debug configuration within intellij, but landed up moving the contents of the static folder under the src/main/webapp folder as your other extjs5 sample project had done and was able to run after moving that folder.

Steve Schreiner

unread,
Jul 1, 2014, 5:01:40 PM7/1/14
to extdire...@googlegroups.com
I noticed this in RepositoryUtil but I did not see it used anywhere in the code?  How would this be used?  Thanks!

public static Pageable createPageRequest(ExtDirectStoreReadRequest request,
final Map<String, String> mapGuiColumn2Dbfield) {

sam

unread,
Jul 1, 2014, 11:17:57 PM7/1/14
to extdire...@googlegroups.com
I could see that its used in UserService.

Ralph Schaer

unread,
Jul 2, 2014, 7:14:18 AM7/2/14
to extdire...@googlegroups.com

Hi

This method is called by the method above with an empty map
public static Pageable createPageRequest(ExtDirectStoreReadRequest request) {
return createPageRequest(request, Collections.<String, String> emptyMap());
}

I copied this method from a project where I had the problem that one column on the client had a different name than the column in the database. So I needed a way to map the gui column to the db column. It's not used in this simple application.

Steve Schreiner

unread,
Jul 2, 2014, 11:44:33 AM7/2/14
to extdire...@googlegroups.com
Hi Ralph,

Thanks again for creating this mongodb example :)  Had a quick question about the UserRepository:

public interface UserRepository extends MongoRepository<User, String> {
Page<User> findByEmailLike(String email, Pageable pageable);
}

I've seen in the the spring mongo project https://github.com/spring-projects/spring-data-mongodb that they extend CrudRepository, being a mongo newbie, is there an advantage to extending one versus the other? And how would that apply to your sample project?

Thanks!

Ralph Schaer

unread,
Jul 2, 2014, 12:58:37 PM7/2/14
to extdire...@googlegroups.com
Hi

Good question. I'm myself a spring-data-mongodb newbie, so I don't know why they added the MongoRepository.

Note

We also provide persistence technology-specific abstractions like e.g. JpaRepository or MongoRepository. Those interfaces extendCrudRepository and expose the capabilities of the underlying persistence technology in addition to the rather generic persistence technology-agnostic interfaces like e.g. CrudRepository.


It also looks like, if I'm understand that correctly, you have to use the MongoRepository interface because @EnableMongoRepositories scans for interfaces extending MongoRepository (chapter 5.2)

Ralph

Reply all
Reply to author
Forward
0 new messages